소스 검색

made code more readable and added hashcode and equals methods to AnimationList

codex 1 년 전
부모
커밋
f12665e8dd

+ 31 - 0
jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/AnimationList.java

@@ -33,6 +33,7 @@ package com.jme3.scene.plugins.fbx;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * Defines animations set that will be created while loading FBX scene
@@ -72,11 +73,41 @@ public class AnimationList {
         cue.lastFrame = lastFrame;
         list.add(cue);
     }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final AnimationList other = (AnimationList)obj;
+        return Objects.equals(this.list, other.list);
+    }
+    
+    @Override
+    public int hashCode() {
+        return 119 + Objects.hashCode(this.list);
+    }    
 
     static class AnimInverval {
         String name;
         String layerName;
         int firstFrame;
         int lastFrame;
+        // hashCode generator, for good measure
+        @Override
+        public int hashCode() {
+            int hash = 7;
+            hash = 29 * hash + Objects.hashCode(this.name);
+            hash = 29 * hash + Objects.hashCode(this.layerName);
+            hash = 29 * hash + this.firstFrame;
+            hash = 29 * hash + this.lastFrame;
+            return hash;
+        }
     }
 }

+ 1 - 1
jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/SceneKey.java

@@ -64,7 +64,7 @@ public class SceneKey extends ModelKey {
         if (!super.equals(other)) {
             return false;
         }
-        if (animList != other.animList && (animList == null || !animList.equals(other.animList))) {
+        if (!Objects.equals(animList, other.animList)) {
             return false;
         }
         return true;

+ 2 - 4
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfModelKey.java

@@ -128,10 +128,8 @@ public class GltfModelKey extends ModelKey {
         if (!super.equals(other)) {
             return false;
         }
-        if (materialAdapters != other.materialAdapters && !materialAdapters.equals(other.materialAdapters)) {
-            return false;
-        }
-        if (extrasLoader != other.extrasLoader && (extrasLoader == null || !extrasLoader.equals(other.extrasLoader))) {
+        if (!Objects.equals(materialAdapters, other.materialAdapters)
+                || !Objects.equals(extrasLoader, other.extrasLoader)) {
             return false;
         }
         return keepSkeletonPose == other.keepSkeletonPose;