-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEdge.java
56 lines (47 loc) · 1.06 KB
/
Edge.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Incognito;
/**
*
* @author Dunni
*/
public class Edge {
//kinda directed, weightless
Vertex to;
Vertex from;
/**
* Constructor
* @param from
* @param to
*/
public Edge(Vertex from, Vertex to){//doesn't check for self loop
this.from = from;
this.to = to;
}
public Vertex getAdjacentVertex(Vertex current){
if(to.equals(current))
return from;
if(from.equals(current))
return to;
return null;
}
@Override
public boolean equals(Object edge){
if(edge.getClass() != this.getClass()){
return false;
}
Edge e = (Edge) edge;
return to.equals(e.to) && from.equals(e.from);
}
public Edge copy(){
return new Edge(from.copy(), to.copy());
}
public Vertex getTo(){
return to;
}
public Vertex getFrom(){
return from;
}
@Override
public String toString(){
return from.toString() + " -> " + to.toString();
}
}