issues/6879: Generate hashCode and equals
@@ -59,18 +59,43 @@ public class Graph {
Vertex(String label) {
this.label = label;
}
+
@Override
- public boolean equals(Object obj) {
- Vertex vertex = (Vertex) obj;
- return vertex.label == label;
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + ((label == null) ? 0 : label.hashCode());
+ return result;
}
+
@Override
- public int hashCode() {
- return label.hashCode();
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Vertex other = (Vertex) obj;
+ if (!getOuterType().equals(other.getOuterType()))
+ return false;
+ if (label == null) {
+ if (other.label != null)
+ return false;
+ } else if (!label.equals(other.label))
+ return false;
+ return true;
}
+
@Override
public String toString() {
return label;
}
+
+
+ private Graph getOuterType() {
+ return Graph.this;
+ }
}
}
\ No newline at end of file
