diff --git a/src/main/NamedCentroid.java b/src/main/NamedCentroid.java new file mode 100644 index 0000000..fd2591e --- /dev/null +++ b/src/main/NamedCentroid.java @@ -0,0 +1,6 @@ +package io.github.auberonedu.equalsLivecode; + +public record NamedCentroid(String name, int r, int c) { +} + + diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/App.java b/src/main/java/io/github/auberonedu/equalsLivecode/App.java index 44717b0..53efd3e 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/App.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/App.java @@ -17,7 +17,7 @@ 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(); + 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..0cd4948 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java @@ -15,6 +15,38 @@ public int getR() { return r; } + @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; + return true; + } + public int getC() { return c; } @@ -22,4 +54,39 @@ public int getC() { public String getName() { return name; } + + // @override + // public boolean equals(Object o){ + // //is these equal to o? + // //ensure r, c and name are all equal between this and o + // //ensure we meet java equals contract + // if(o== null) return false; + + // if(!this.getClass().equals(o.getClass())){ + // return false; + // } + + // Centroid other = (Centroid) o; + + // if(r !=other.r) return false; + // if(c != other.c) return false; + + // if(name == null){ + // return other.name == null; + // // if(other.name == null) { + // // return true; + // // } + // // else{ + // // //other.name is not null + // // return false; + // // } + // } + + // return this.name.equals(other.name); + // // if(!this.name.equals(other.name)) { + // // return false; + // // }else{ + // // return true; + // //} + // } }