diff options
author | Julien Gouesse <[email protected]> | 2014-08-08 23:34:58 +0200 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2014-08-08 23:34:58 +0200 |
commit | 23e3e4dc76c78a8d84f8909618b9e729fd391127 (patch) | |
tree | f260d50a78ef7e840c8f6defde1e8a13e2003f25 /ardor3d-core | |
parent | 83554a405f4e806d5b2252312c960d1d0131bbad (diff) |
Implements the hashCode() method of ShaderVariable
Diffstat (limited to 'ardor3d-core')
-rw-r--r-- | ardor3d-core/src/main/java/com/ardor3d/util/shader/ShaderVariable.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/util/shader/ShaderVariable.java b/ardor3d-core/src/main/java/com/ardor3d/util/shader/ShaderVariable.java index 6ea3c80..13f97af 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/util/shader/ShaderVariable.java +++ b/ardor3d-core/src/main/java/com/ardor3d/util/shader/ShaderVariable.java @@ -40,20 +40,41 @@ public class ShaderVariable implements Savable { } @Override - public boolean equals(final Object o) { - if (this == o) { + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + variableID; + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ShaderVariable)) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { return false; } - final ShaderVariable comp = (ShaderVariable) o; + final ShaderVariable other = (ShaderVariable) obj; if (variableID != -1) { - return comp.variableID == variableID; - } else if (comp.variableID != -1) { - return comp.variableID == variableID; + return other.variableID == variableID; + } else if (other.variableID != -1) { + return other.variableID == variableID; + } else { + return (equals(name, other.name)); + } + } + + // TODO replace it by java.util.Objects.equals(Object, Object) + private boolean equals(final Object a, final Object b) { + if (a == b) { + return true; } else { - return (name.equals(comp.name)); + return a != null && a.equals(b); } } |