Merge pull request #6888 from eugenp/Issue-6879

issues/6879: Generate hashCode and equals
This commit is contained in:
Eric Martin 2019-05-02 23:10:27 -05:00 committed by GitHub
commit dbfb230956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 6 deletions

View File

@ -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;
}
@Override
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
public String toString() {
return label;
}
private Graph getOuterType() {
return Graph.this;
}
}
}