issues/6879: Generate hashCode and equals

This commit is contained in:
eric-martin 2019-05-02 23:03:00 -05:00
parent 4cc3f3413c
commit 5adaadbfc5
1 changed files with 31 additions and 6 deletions

View File

@ -59,18 +59,43 @@ public class Graph {
Vertex(String label) { Vertex(String label) {
this.label = label; this.label = label;
} }
@Override
public boolean equals(Object obj) {
Vertex vertex = (Vertex) obj;
return vertex.label == label;
}
@Override @Override
public int hashCode() { public int hashCode() {
return label.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 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 @Override
public String toString() { public String toString() {
return label; return label;
} }
private Graph getOuterType() {
return Graph.this;
}
} }
} }