Skip to content

Commit c4c8da3

Browse files
committed
New implementation of hashCode() + test
1 parent 5e5660b commit c4c8da3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/io/github/parubok/stream/TableCell.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ public int get(Field field) {
6666

6767
@Override
6868
public int hashCode() {
69-
int result = 17;
70-
result = 37 * result + row;
71-
result = 37 * result + col;
72-
return result;
69+
return Integer.hashCode(row + col);
7370
}
7471

7572
@Override

src/test/java/io/github/parubok/stream/TableCellTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,13 @@ public void get_field() {
224224
Assertions.assertEquals(10, c.get(TableCell.ROW));
225225
Assertions.assertEquals(2, c.get(TableCell.COLUMN));
226226
}
227+
228+
@Test
229+
public void hashCode_() {
230+
for (int i = 0; i < 100; i++) {
231+
Assertions.assertEquals(new TableCell(i, i).hashCode(), new TableCell(i, i).hashCode());
232+
Assertions.assertEquals(new TableCell(0, i).hashCode(), new TableCell(0, i).hashCode());
233+
Assertions.assertEquals(new TableCell(i, 0).hashCode(), new TableCell(i, 0).hashCode());
234+
}
235+
}
227236
}

0 commit comments

Comments
 (0)