forked from sherxon/AlgoDS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
91 lines (70 loc) · 1.87 KB
/
Copy pathVertex.java
File metadata and controls
91 lines (70 loc) · 1.87 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
package ds.graph;
import java.util.HashSet;
import java.util.Set;
/**
* Created by sherxon on 1/1/17.
*/
public class Vertex<T> implements Comparable<Vertex<T>> {
private T value;
private Set<Vertex<T>> neighbors; // used with Unweighted graphs
private Vertex<T> parent; // used in dfs and bfs
private boolean visited; //used for bfs and dfs
private Number weight;
public Vertex(T value) {
this.value = value;
this.neighbors = new HashSet<>();
}
@Override
public String toString() {
return "Vertex{" +
"value=" + value + '}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Vertex<?> vertex = (Vertex<?>) o;
return value.equals(vertex.value);
}
@Override
public int hashCode() {
return value.hashCode();
}
public Number getWeight() {
return weight;
}
public void setWeight(Number weight) {
this.weight = weight;
}
public void addNeighbor(Vertex<T> vertex){
this.neighbors.add(vertex);
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public Set<Vertex<T>> getNeighbors() {
return neighbors;
}
public Vertex<T> getParent() {
return parent;
}
public void setParent(Vertex parent) {
this.parent = parent;
}
public boolean isVisited() {
return visited;
}
public void setVisited(boolean visited) {
this.visited = visited;
}
public void removeNeighrbor(Vertex<T> vertex) {
this.neighbors.remove(vertex);
}
@Override
public int compareTo(Vertex<T> o) {
return (int) (this.weight.doubleValue() - o.weight.doubleValue());
}
}