-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPosition.java
More file actions
58 lines (50 loc) · 1.18 KB
/
Position.java
File metadata and controls
58 lines (50 loc) · 1.18 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
/*
Author: Dan Levy
Email: dlevy2016@my.fit.edu
Course: CSE 2010
Section: 02
Description:
* Holds the row and column of a vertex in a grid
*/
public class Position implements Comparable<Position> {
private int _row;
private int _col;
/*
* Constructs a new position object holding the vertex's row and column in a grid
*/
public Position(int row, int col) {
this._row = row;
this._col = col;
}
public int getRow() {
return this._row;
}
public int getCol() {
return this._col;
}
public void setRow(int row) {
this._row = row;
}
public void setCol(int col) {
this._col = col;
}
/*
* Returns an ordered pair containing the row and column of the vertex in a grid
*/
@Override
public String toString() {
return "(" + this._row + "," + this._col + ")";
}
/*
* Compares this position with the other given vertex
* Compares by multiplying the row by 10 and adding the column onto it (ex. (2,3) = 23 and (3,2) = 32
*/
@Override
public int compareTo(Position other) {
return ((this._row * 10) + this._col) - ((other._row * 10) + other._col);
}
@Override
public boolean equals(Object other) {
return this.compareTo((Position) other) == 0;
}
}