Просмотр исходного кода

Merge pull request #780 from FridaTveit/SaddlePointsImproveErrorMessage

saddle-points: implement toString for matrix coordinate
FridaTveit 9 лет назад
Родитель
Сommit
6accdde2e3

+ 32
- 30
exercises/saddle-points/.meta/src/reference/java/MatrixCoordinate.java Просмотреть файл

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
+    }
31
 }
33
 }

+ 24
- 22
exercises/saddle-points/src/main/java/MatrixCoordinate.java Просмотреть файл

1
 class MatrixCoordinate {
1
 class MatrixCoordinate {
2
+    private final int row;
3
+    private final int col;
2
 
4
 
3
-  private final int row;
5
+    MatrixCoordinate(final int row, final int col) {
6
+        this.row = row;
7
+        this.col = col;
8
+    }
4
 
9
 
5
-  private final int col;
10
+    @Override
11
+    public String toString() {
12
+        return "Row: " + row + ", Column: " + col;
13
+    }
6
 
14
 
7
-  MatrixCoordinate(final int row, final int col) {
8
-    this.row = row;
9
-    this.col = col;
10
-  }
15
+    // Generated equals and hashcode.
11
 
16
 
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;
13
 
21
 
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;
18
 
23
 
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
+    }
30
 
26
 
27
+    @Override
28
+    public int hashCode() {
29
+        int result = row;
30
+        result = 31 * result + col;
31
+        return result;
32
+    }
31
 }
33
 }