From 90f32dc7031e25b41901b988024a37c0ca44ec92 Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sat, 14 Apr 2012 19:38:42 +0000 Subject: [PATCH] * 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 --- .../jme3/scene/plugins/ogre/OgreMeshKey.java | 30 ++++++++++++ .../ogre/matext/MaterialExtensionSet.java | 25 +++++----- .../plugins/ogre/matext/OgreMaterialKey.java | 47 +++++++++++++++---- 3 files changed, 80 insertions(+), 22 deletions(-) diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java index 1141944b2..617f25a2a 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java +++ b/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; } diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java index 2c81e7bf9..0cd9dfd60 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java +++ b/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 extensions - = new HashMap(); + + private HashMap extensions = new HashMap(); private HashMap> nameMappings = new HashMap>(); /** * 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 list = nameMappings.get(name); - if(list==null){ + if (list == null) { list = new ArrayList(); nameMappings.put(name, list); } list.add(alias); } - - public List getNameMappings(String name){ + + public List getNameMappings(String name) { return nameMappings.get(name); } } diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/OgreMaterialKey.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/OgreMaterialKey.java index 8c5137bbe..c300783ef 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/OgreMaterialKey.java +++ b/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; /** - * OgreMaterialKey allows specifying material extensions, - * which map from Ogre3D base materials to jME3 materials + * OgreMaterialKey allows specifying material extensions, which map + * from Ogre3D base materials to jME3 materials */ public class OgreMaterialKey extends AssetKey { 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 null to disable this functionality. + * Set the {@link MaterialExtensionSet} to use for mapping base materials to + * jME3 matdefs when loading. Set to + * null 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() {