Skip to content

Commit 49db0af

Browse files
committed
saddle-points: implement toString for matrix coordinate
This is to improve the error message when comparison fails.
1 parent 37e3c79 commit 49db0af

2 files changed

Lines changed: 56 additions & 52 deletions

File tree

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
final class MatrixCoordinate {
2-
3-
private final int row;
4-
5-
private final int col;
6-
7-
MatrixCoordinate(final int row, final int col) {
8-
this.row = row;
9-
this.col = col;
10-
}
11-
12-
// Generated equals and hashcode.
13-
14-
@Override
15-
public boolean equals(final Object o) {
16-
if (this == o) return true;
17-
if (o == null || getClass() != o.getClass()) return false;
18-
19-
final MatrixCoordinate that = (MatrixCoordinate) o;
20-
21-
return row == that.row && col == that.col;
22-
}
23-
24-
@Override
25-
public int hashCode() {
26-
int result = row;
27-
result = 31 * result + col;
28-
return result;
29-
}
30-
1+
class MatrixCoordinate {
2+
private final int row;
3+
private final int col;
4+
5+
MatrixCoordinate(final int row, final int col) {
6+
this.row = row;
7+
this.col = col;
8+
}
9+
10+
@Override
11+
public String toString() {
12+
return "Row: " + row + ", Column: " + col;
13+
}
14+
15+
// Generated equals and hashcode.
16+
17+
@Override
18+
public boolean equals(final Object o) {
19+
if (this == o) return true;
20+
if (o == null || getClass() != o.getClass()) return false;
21+
22+
final MatrixCoordinate that = (MatrixCoordinate) o;
23+
24+
return row == that.row && col == that.col;
25+
}
26+
27+
@Override
28+
public int hashCode() {
29+
int result = row;
30+
result = 31 * result + col;
31+
return result;
32+
}
3133
}
Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
class MatrixCoordinate {
2+
private final int row;
3+
private final int col;
24

3-
private final int row;
5+
MatrixCoordinate(final int row, final int col) {
6+
this.row = row;
7+
this.col = col;
8+
}
49

5-
private final int col;
10+
@Override
11+
public String toString() {
12+
return "Row: " + row + ", Column: " + col;
13+
}
614

7-
MatrixCoordinate(final int row, final int col) {
8-
this.row = row;
9-
this.col = col;
10-
}
15+
// Generated equals and hashcode.
1116

12-
// Generated equals and hashcode.
17+
@Override
18+
public boolean equals(final Object o) {
19+
if (this == o) return true;
20+
if (o == null || getClass() != o.getClass()) return false;
1321

14-
@Override
15-
public boolean equals(final Object o) {
16-
if (this == o) return true;
17-
if (o == null || getClass() != o.getClass()) return false;
22+
final MatrixCoordinate that = (MatrixCoordinate) o;
1823

19-
final MatrixCoordinate that = (MatrixCoordinate) o;
20-
21-
return row == that.row && col == that.col;
22-
}
23-
24-
@Override
25-
public int hashCode() {
26-
int result = row;
27-
result = 31 * result + col;
28-
return result;
29-
}
24+
return row == that.row && col == that.col;
25+
}
3026

27+
@Override
28+
public int hashCode() {
29+
int result = row;
30+
result = 31 * result + col;
31+
return result;
32+
}
3133
}

0 commit comments

Comments
 (0)