-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
93 lines (77 loc) · 1.66 KB
/
Vertex.java
File metadata and controls
93 lines (77 loc) · 1.66 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
93
/**
* Vertex class created from tutorial, customized for
* My Routine program. Creates places as vertices and
* allows for tracking of adjacent places traveled to
* in the neighborhood list
*/
package MyRoutine;
import java.util.ArrayList;
public class Vertex
{
private ArrayList<Edge> neighborhood;
private String place;
private int visits;
public Vertex(String place)
{
this.place = place;
this.neighborhood = new ArrayList<Edge>();
visits = 1;
}
//add edge to neighborhood
public void addNeighbor(Edge edge)
{
if(this.neighborhood.contains(edge))
{
return;//future spot to increment paths
}
this.neighborhood.add(edge);
}
//check if vertex contains an edge
public boolean containsNeighbor(Edge other)
{
return this.neighborhood.contains(other);
}
public Edge getNeighbor(int index)
{
return this.neighborhood.get(index);
}
//probably not needed for app
public int getNeighborCount()
{
return this.neighborhood.size();
}
//get string label for current vertex
public String getLabel()
{
return this.place;
}
//custom to string method for vertex
public String toString()
{
return "Place: " + place + " Visits: " + visits;
}
public int hashCode()
{
return this.place.hashCode();
}
//compare vertices, return true if equal
public boolean equals(Object other)
{
if(!(other instanceof Vertex))
{
return false;
}
Vertex v = (Vertex)other;
return this.place.equals(v.place);
}
//get neighbors of current vertex
public ArrayList<Edge> getNeighbors()
{
return new ArrayList<Edge>(this.neighborhood);
}
//method to increment visits to current place
public void visit()
{
visits++;
}
}