-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.java
More file actions
92 lines (76 loc) · 1.72 KB
/
Edge.java
File metadata and controls
92 lines (76 loc) · 1.72 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**Edge class that builds a
*/
package MyRoutine;
public class Edge implements Comparable<Edge>
{
private Vertex one, two;
private int trips;//future value to track trips along edge in future
//create an edge with default of one trip
public Edge(Vertex one, Vertex two)
{
this(one, two, 1);
}
//create an edge with a specified number of trips
public Edge (Vertex one, Vertex two, int trips)
{
this.one = (one.getLabel().compareTo(two.getLabel())
<= 0) ? one : two;
this.two = (this.one == one) ? two : one;
this.trips = trips;
}
public Vertex getNeighbor(Vertex current)
{
if (!( current.equals(one) || current.equals(two)))
{ return null; }
return (current.equals(one)) ? two : one;
}
//future method to add trip to current edge
public void addTrip()
{
this.trips++;
}
//general getter methods for vertices and trips
public Vertex getOne()
{
return this.one;
}
public Vertex getTwo()
{
return this.two;
}
public int getTrips()
{
return this.trips;
}
//setter for number of trips
public void setTrips(int trips)
{
this.trips = trips;
}
//compares edge trips
public int compareTo(Edge other)
{
return this.trips - other.trips;
}
//toString method for edge
public String toString()
{
return "[{ " + one.getLabel() + " <-> " + two.getLabel() + " }]";
//+ ", "
//+ trips + " trips ]";//trips not function in current build
}
//hashcode of edge
public int hashCode()
{
return (one.getLabel() + two.getLabel()).hashCode();
}
//compare edges, return true if same
public boolean equals(Object other)
{
if (!( other instanceof Edge))
{ return false; }
Edge e = (Edge)other;
return e.one.equals(this.one) &&
e.two.equals(this.two);
}
}