-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosition.java
75 lines (70 loc) · 1.76 KB
/
Position.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
*
* Created by KaninJaevel on 07/04/2016.
*/
public class Position {
private int x;
private int y;
/**
* @param x - int representing x value
* @param y - int representing y value
*/
public Position(int x, int y){
this.x=x;
this.y=y;
}
/**
* Method that returns current x value;
* @return x - representad as int.
*/
public int getX(){return x;}
/**
* Method that returns current y value;
* @return y - representad as int.
*/
public int getY(){return y;}
/**
* Method that returns position that is
* south of current position.
* @return Position
*/
public Position getPosToSouth(){return new Position(x,y+1);}
/**
* Method that returns position that is
* north of current position.
* @return Position
*/
public Position getPosToNorth(){
return new Position(x,y-1);
}
/**
* Method that returns position that is
* east of current position.
* @return Position
*/
public Position getPosToEast(){
return new Position(x+1,y);
}
/**
* Method that returns position that is
* west of current position.
* @return Position
*/
public Position getPosToWest(){return new Position(x-1,y);}
/**
* Method to compare objects.
* @param o - Position to be compared.
* @return boolean representing if they are equal
*/
public boolean equals(Object o){
if(o==this)
return true;
return false;
}
public int hashCode(){
int hash = 1;
hash = (hash + getX()) * 113;
hash = (hash + getY()) * 109;
return hash;
}
}