Skip to contentMethod: hashCode()
      1: package de.fhdw.gaming.ipspiel23.c4.domain.impl.validation;
2: 
3: import de.fhdw.gaming.core.ui.InputProviderException;
4: 
5: import static de.fhdw.gaming.ipspiel23.c4.domain.impl.validation.C4BoardLimits.MIN_COLUMN_COUNT;
6: import static de.fhdw.gaming.ipspiel23.c4.domain.impl.validation.C4BoardLimits.MIN_ROW_COUNT;
7: import static de.fhdw.gaming.ipspiel23.c4.domain.impl.validation.C4BoardLimits.MAX_COLUMN_COUNT;
8: import static de.fhdw.gaming.ipspiel23.c4.domain.impl.validation.C4BoardLimits.MAX_ROW_COUNT;
9: 
10: /**
11:  * The dimensions of a board, to be used for validation.
12:  */
13: class C4BoardDimensions {
14:     /**
15:      * The currently specified number of rows a board will have.
16:      */
17:     private int rowCount;
18: 
19:     /**
20:      * The currently specified number of columns a board will have.
21:      */
22:     private int columnCount;
23: 
24:     /**
25:      * Creates a new instance of {@link C4BoardDimensions}.
26:      * 
27:      * @param rowCount The currently specified number of rows a board will have.
28:      * @param columnCount The currently specified number of columns a board will have.
29:      */
30:     public C4BoardDimensions(final int rowCount, final int columnCount) {
31:         this.rowCount = rowCount;
32:         this.columnCount = columnCount;
33:     }
34: 
35:     /**
36:      * Gets the currently specified number of rows a board will have.
37:      */
38:     public int getRowCount() {
39:         return rowCount;
40:     }
41: 
42:     /**
43:      * Sets the currently specified number of rows a board will have.
44:      * @param rowCount the new row count
45:      */
46:     public void setRowCount(final int rowCount) {
47:         this.rowCount = rowCount;
48:     }
49: 
50:     /**
51:      * Gets the currently specified number of columns a board will have.
52:      */
53:     public int getColumnCount() {
54:         return columnCount;
55:     }
56: 
57:     /**
58:      * Sets the currently specified number of columns a board will have.
59:      * @param columnCount the new column count
60:      */
61:     public void setColumnCount(final int columnCount) {
62:         this.columnCount = columnCount;
63:     }
64: 
65:     /**
66:      * Asserts that the currently specified number of rows and columns is valid.
67:      * @throws InputProviderException if the currently specified number of rows or columns is invalid
68:      */
69:     public void assertStaticLimits() throws InputProviderException {
70:         if (this.rowCount < MIN_ROW_COUNT) {
71:             throw new InputProviderException("The specified number of rows is too small: the number of rows "
72:                 + "must be at least " + MIN_ROW_COUNT + ".");
73:         }
74:         if (this.columnCount < MIN_COLUMN_COUNT) {
75:             throw new InputProviderException("The specified number of columns is too small: the number of columns "
76:                 + "must be at least " + MIN_COLUMN_COUNT + ".");
77:         }
78:         if (this.rowCount > MAX_ROW_COUNT) {
79:             throw new InputProviderException("The specified number of rows is too large: the number of rows "
80:                 + "must not exceed " + MAX_ROW_COUNT + ".");
81:         }
82:         if (this.columnCount > MAX_COLUMN_COUNT) {
83:             throw new InputProviderException("The specified number of columns is too large: the number of columns "
84:                 + "must not exceed " + MAX_COLUMN_COUNT + ".");
85:         }
86:     }
87: 
88:     @Override
89:     public boolean equals(final Object object) {
90:         if (object == null) {
91:             return false;
92:         } 
93:         if (!(object instanceof C4BoardDimensions)) {
94:             return false;
95:         }
96:         final C4BoardDimensions other = (C4BoardDimensions) object;
97:         return rowCount == other.rowCount && columnCount == other.columnCount;
98:     }
99: 
100:     @Override
101:     public int hashCode() {
102:         return rowCount * 31 + columnCount;
103:     }
104: }