-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
70 lines (58 loc) · 1.41 KB
/
Vertex.java
File metadata and controls
70 lines (58 loc) · 1.41 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
import java.util.Objects;
/**
* A vertex with x and y coordinate
* @author Saveri
*
*/
public class Vertex
{
// Vertex coordinates
private int x;
private int y;
/**
* Constructs a new vertex with given name
* @param vertName
*/
public Vertex(int xCoord, int yCoord)
{
x = xCoord;
y = yCoord;
}
/**
* Gets x-coordinate of vertex
* @return x-coordinate of vertex
*/
public int getX()
{
return x;
}
/**
* Gets y-coordinate of vertex
* @return y-coordinate of vertex
*/
public int getY()
{
return y;
}
// To make vertex comparisons based on x,y-coordinate of a vertex
@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 Vertex)) {
return false;
}
// typecast o to Complex so that we can compare data members
Vertex c = (Vertex) o;
// Compare the data members and return accordingly
return (x == c.x) && (y == c.y);
}
@Override
public int hashCode() {
return Objects.hash(x,y);
}
}