Browse Source

* Proper equals/hashCode methods in OgreMaterialKey/OgreMeshKey
* Formatting in MaterialExtensionSet

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9305 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Sha..rd 13 years ago
parent
commit
90f32dc703

+ 30 - 0
engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java

@@ -66,6 +66,36 @@ public class OgreMeshKey extends ModelKey {
         this.materialName = materialName;
     }
 
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final OgreMeshKey other = (OgreMeshKey) obj;
+        if (!super.equals(other)) {
+            return false;
+        }
+        if (this.materialList != other.materialList && (this.materialList == null || !this.materialList.equals(other.materialList))) {
+            return false;
+        }
+        if ((this.materialName == null) ? (other.materialName != null) : !this.materialName.equals(other.materialName)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 5;
+        hash = 31 * hash + (super.hashCode());
+        hash = 31 * hash + (this.materialList != null ? this.materialList.hashCode() : 0);
+        hash = 31 * hash + (this.materialName != null ? this.materialName.hashCode() : 0);
+        return hash;
+    }
+    
     public MaterialList getMaterialList() {
         return materialList;
     }

+ 13 - 12
engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java

@@ -29,7 +29,6 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 package com.jme3.scene.plugins.ogre.matext;
 
 import java.util.ArrayList;
@@ -42,44 +41,46 @@ import java.util.List;
  * {@link OgreMaterialKey}s used.
  */
 public class MaterialExtensionSet {
-    private HashMap<String, MaterialExtension> extensions
-            = new HashMap<String, MaterialExtension>();
+
+    private HashMap<String, MaterialExtension> extensions = new HashMap<String, MaterialExtension>();
     private HashMap<String, List<String>> nameMappings = new HashMap<String, List<String>>();
 
     /**
      * Adds a new material extension to the set of extensions.
+     *
      * @param extension The {@link MaterialExtension} to add.
      */
-    public void addMaterialExtension(MaterialExtension extension){
+    public void addMaterialExtension(MaterialExtension extension) {
         extensions.put(extension.getBaseMaterialName(), extension);
     }
 
     /**
-     * Returns the {@link MaterialExtension} for a given Ogre3D base
-     * material name.
+     * Returns the {@link MaterialExtension} for a given Ogre3D base material
+     * name.
      *
      * @param baseMatName The ogre3D base material name.
      * @return {@link MaterialExtension} that is set, or null if not set.
      */
-    public MaterialExtension getMaterialExtension(String baseMatName){
+    public MaterialExtension getMaterialExtension(String baseMatName) {
         return extensions.get(baseMatName);
     }
-    
+
     /**
      * Adds an alternative name for a material
+     *
      * @param name The material name to be found in a .mesh.xml file
      * @param alias The material name to be found in a .material file
      */
-    public void setNameMapping(String name, String alias){
+    public void setNameMapping(String name, String alias) {
         List<String> list = nameMappings.get(name);
-        if(list==null){
+        if (list == null) {
             list = new ArrayList<String>();
             nameMappings.put(name, list);
         }
         list.add(alias);
     }
-    
-    public List<String> getNameMappings(String name){
+
+    public List<String> getNameMappings(String name) {
         return nameMappings.get(name);
     }
 }

+ 37 - 10
engine/src/ogre/com/jme3/scene/plugins/ogre/matext/OgreMaterialKey.java

@@ -29,42 +29,69 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 package com.jme3.scene.plugins.ogre.matext;
 
 import com.jme3.asset.AssetKey;
 import com.jme3.material.MaterialList;
 
 /**
- * <code>OgreMaterialKey</code> allows specifying material extensions,
- * which map from Ogre3D base materials to jME3 materials
+ * <code>OgreMaterialKey</code> allows specifying material extensions, which map
+ * from Ogre3D base materials to jME3 materials
  */
 public class OgreMaterialKey extends AssetKey<MaterialList> {
 
     private MaterialExtensionSet matExts;
 
-    public OgreMaterialKey(String name){
+    public OgreMaterialKey(String name) {
         super(name);
     }
 
-    public OgreMaterialKey(){
+    public OgreMaterialKey() {
         super();
     }
 
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final OgreMaterialKey other = (OgreMaterialKey) obj;
+        if (!super.equals(other)) {
+            return false;
+        }
+        if (this.matExts != other.matExts && (this.matExts == null || !this.matExts.equals(other.matExts))) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 5;
+        hash = 71 * hash + (super.hashCode());
+        hash = 71 * hash + (this.matExts != null ? this.matExts.hashCode() : 0);
+        return hash;
+    }
+    
     /**
-     * Set the {@link MaterialExtensionSet} to use for mapping
-     * base materials to jME3 matdefs when loading.
-     * Set to <code>null</code> to disable this functionality.
+     * Set the {@link MaterialExtensionSet} to use for mapping base materials to
+     * jME3 matdefs when loading. Set to
+     * <code>null</code> to disable this functionality.
      *
      * @param matExts The {@link MaterialExtensionSet} to use
      */
-    public void setMaterialExtensionSet(MaterialExtensionSet matExts){
+    public void setMaterialExtensionSet(MaterialExtensionSet matExts) {
         this.matExts = matExts;
     }
 
     /**
      * Returns the {@link MaterialExtensionSet} previously set using
-     * {@link OgreMaterialKey#setMaterialExtensionSet(com.jme3.scene.plugins.ogre.matext.MaterialExtensionSet) } method.
+     * {@link OgreMaterialKey#setMaterialExtensionSet(com.jme3.scene.plugins.ogre.matext.MaterialExtensionSet)
+     * } method.
+     *
      * @return the {@link MaterialExtensionSet}
      */
     public MaterialExtensionSet getMaterialExtensionSet() {