Skip to content

Package: OthelloPosition

OthelloPosition

nameinstructionbranchcomplexitylinemethod
OthelloPosition(int, int)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
equals(Object)
M: 0 C: 22
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getColumn()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getRow()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
of(int, int)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
offset(int, int)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * Copyright © 2020-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of othello-core.
5: *
6: * Othello-core is free software: you can redistribute it and/or modify
7: * it under the terms of the GNU General Public License as published by
8: * the Free Software Foundation, either version 3 of the License, or
9: * (at your option) any later version.
10: *
11: * Othello-core is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with othello-core. If not, see <http://www.gnu.org/licenses/>.
18: */
19: package de.fhdw.gaming.othello.core.domain;
20:
21: /**
22: * Represents a field position on a board. It contains a row number and a column number (both zero-based).
23: */
24: public final class OthelloPosition {
25:
26: /**
27: * The row index.
28: */
29: private final int row;
30: /**
31: * The column index.
32: */
33: private final int column;
34:
35: /**
36: * Creates a position on an Othello board.
37: *
38: * @param row The row number (zero based).
39: * @param column The column number (zero-based).
40: */
41: private OthelloPosition(final int row, final int column) {
42: this.row = row;
43: this.column = column;
44: }
45:
46: /**
47: * Creates a position on an Othello board.
48: *
49: * @param row The row number (zero based).
50: * @param column The column number (zero-based).
51: * @return The position.
52: */
53: public static OthelloPosition of(final int row, final int column) {
54: return new OthelloPosition(row, column);
55: }
56:
57: /**
58: * Returns the zero-based row number.
59: */
60: public int getRow() {
61: return this.row;
62: }
63:
64: /**
65: * Returns the zero-based column number.
66: */
67: public int getColumn() {
68: return this.column;
69: }
70:
71: /**
72: * Creates a position relative to this one. The position is not checked against any bounds.
73: *
74: * @param rowOffset The row offset. May be negative, positive, or zero.
75: * @param columnOffset The column offset. May be negative, positive, or zero.
76: * @return The resulting position.
77: */
78: public OthelloPosition offset(final int rowOffset, final int columnOffset) {
79: return OthelloPosition.of(this.row + rowOffset, this.column + columnOffset);
80: }
81:
82: @Override
83: public String toString() {
84: return String.format("%c%d", (char) (this.column + 'A'), this.row + 1);
85: }
86:
87: @Override
88: public int hashCode() {
89: return this.row ^ this.column;
90: }
91:
92: @Override
93: public boolean equals(final Object obj) {
94:• if (obj instanceof OthelloPosition) {
95: final OthelloPosition other = (OthelloPosition) obj;
96:• return this.column == other.column && this.row == other.row;
97: }
98: return false;
99: }
100: }