-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphEdgePredecessor.java
executable file
·55 lines (44 loc) · 1.5 KB
/
GraphEdgePredecessor.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
package com.example.graph;
import java.util.Objects;
public class GraphEdgePredecessor implements Comparable<GraphEdgePredecessor> {
protected int indexPredecessor;
protected boolean visited;
protected int indexVertex;
protected double weight;
public GraphEdgePredecessor(int indexVertex, double weight, int indexPredecessor) {
this.visited = false;
this.indexPredecessor = indexPredecessor;
this.indexVertex = indexVertex;
this.weight = weight;
}
public GraphEdgePredecessor(int indexVertex, double weight) {
this(indexVertex, weight, 0);
}
/**
* Compares two edges edge by the weight.
*
* @param graphEdgeWeightPredecessor {@link com.example.graph.GraphEdgePredecessor} Edge to compare
* @return 1 if the current Edge has heigher weight than the given edge, 0
* if same weight, -1 otherwise
*/
@Override
public int compareTo(GraphEdgePredecessor graphEdgeWeightPredecessor) {
return Double.compare(this.weight, graphEdgeWeightPredecessor.weight);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GraphEdgePredecessor that)) return false;
return getIndexVertex() == that.getIndexVertex();
}
@Override
public int hashCode() {
return Objects.hash(getIndexVertex());
}
public int getIndexVertex() {
return indexVertex;
}
public double getWeight() {
return weight;
}
}