-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.java
More file actions
42 lines (38 loc) · 1.01 KB
/
Edge.java
File metadata and controls
42 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.HashSet;
public class Edge {
// Node x;
// Node y;
HashSet<Node> nodes = new HashSet<Node>();
public Edge(Node x, Node y) {
if (x == null) {
throw new IllegalArgumentException("x passed to edge constructor was null");
} else if (y == null) {
throw new IllegalArgumentException("y passed to edge constructor was null");
}
// this.x = x;
// this.y = y;
nodes.add(x);
nodes.add(y);
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Edge)) {
return false;
}
Edge o = (Edge)other;
if (this.nodes.size() != o.nodes.size()) {
return false;
}
for (Node n : this.nodes) {
if (!o.nodes.contains(n)) {
return false;
}
}
return true;
// return (this.nodes == other.nodes);
}
@Override
public int hashCode() {
return nodes.hashCode();
}
}