diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/App.java b/src/main/java/io/github/auberonedu/equalsLivecode/App.java index 53efd3e..8b51a12 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/App.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/App.java @@ -17,7 +17,14 @@ public static void main(String[] args) { System.out.println("Result of locA == locB " + (locA == locB)); System.out.println("Result of locA.equals(locB) " + locA.equals(locB)); - videoDemo(); + Set centroids = new HashSet<>(); + System.out.println(locA.hashCode()); + System.out.println(locB.hashCode()); + centroids.add(locA); + centroids.add(locB); + System.out.println(centroids.size()); + + //videoDemo(); } // We will look at this a bit later in the livecode, please ignore for first part diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java index b0e343a..4a18769 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java @@ -19,7 +19,55 @@ public int getC() { return c; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + r; + result = prime * result + c; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Centroid other = (Centroid) obj; + if (r != other.r) + return false; + if (c != other.c) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + public String getName() { return name; } +/** + @Override + public boolean equals(Object o){ + if(o == null) return false; + if(getClass() != o.getClass()) return false; + Centroid other = (Centroid) o; + if(r != other.r) return false; + if(c != other.c) return false; + if(name == null){ + if(other.name == null) return true; + if(other.name != null) return false; + } + if(!name.equals(other.name)) return false; + return true; + } + +*/ }