-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistance.java
More file actions
85 lines (76 loc) · 1.74 KB
/
Distance.java
File metadata and controls
85 lines (76 loc) · 1.74 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
/**
* Distance contains two attributes - a vertex and its distance from source
* @author Saveri
*
*/
public class Distance
{
private Vertex v;
private double minDist;
private Vertex src;
/**
* Constructs a Distance object with the given info
* @param v - Vertex
* @param d - distance
*/
public Distance(Vertex v, double d) {
this.v = v;
this.minDist = d;
src = null;
}
/**
* set src info for min distance
* @param v
*/
public void setSrc(Vertex v) {
src = v;
}
/**
* set src info for min distance
* @param v
*/
public Vertex getSrc() {
return src;
}
/**
* Sets minimum distance by a given amount
* @param d
*/
public void setMinDistance(double d)
{
minDist = d;
}
/**
* Gets the minimum distance from source
* @return minimum distance from source
*/
public double getMinDistance()
{
return minDist;
}
/**
* Gets the vertex
* @return
*/
public Vertex getVertex()
{
return v;
}
// To make vertex comparisons based on x,y-coordinate of the Vertex parameter
@Override
public boolean equals(Object o) {
// If the object is compared with itself then return true
if (o == this) {
return true;
}
/* Check if o is an instance of Complex or not
"null instanceof [type]" also returns false */
if (!(o instanceof Distance)) {
return false;
}
// typecast o to Complex so that we can compare data members
Distance c = (Distance) o;
// Compare the data members and return accordingly
return (v.getX() == c.v.getX() && v.getY() == c.v.getY());
}
}