From 23e3e4dc76c78a8d84f8909618b9e729fd391127 Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Fri, 8 Aug 2014 23:34:58 +0200 Subject: Implements the hashCode() method of ShaderVariable --- .../com/ardor3d/util/shader/ShaderVariable.java | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'ardor3d-core') 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); } } -- cgit v1.2.3