diff --git a/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java b/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java index a40709d..424641c 100644 --- a/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java +++ b/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java @@ -26,4 +26,41 @@ public class Wesen { this.staerke = staerke; } + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + staerke; + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Wesen other = (Wesen) obj; + if (name == null) { + if (other.name != null) { + return false; + } + } + else if (!name.equals(other.name)) { + return false; + } + return staerke == other.staerke; + } }