Skip to content

Package: C4SolutionHeavy

C4SolutionHeavy

nameinstructionbranchcomplexitylinemethod
C4SolutionHeavy(IC4Player, IC4Position, IC4Position, C4Direction, IC4Field[])
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
equals(Object)
M: 6 C: 45
88%
M: 3 C: 13
81%
M: 2 C: 7
78%
M: 0 C: 11
100%
M: 0 C: 1
100%
getContainingFields()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDirection()
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%
getEndPosition()
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%
getOwner()
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%
getStartPosition()
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: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
size()
M: 0 C: 4
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: 40
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: package de.fhdw.gaming.ipspiel23.c4.domain.impl;
2:
3: import java.util.Arrays;
4:
5: import de.fhdw.gaming.ipspiel23.c4.domain.C4Direction;
6: import de.fhdw.gaming.ipspiel23.c4.domain.IC4Field;
7: import de.fhdw.gaming.ipspiel23.c4.domain.IC4Position;
8: import de.fhdw.gaming.ipspiel23.c4.domain.IC4Solution;
9: import de.fhdw.gaming.ipspiel23.c4.domain.IC4Player;
10: import de.fhdw.gaming.ipspiel23.c4.domain.IC4SolutionSlim;
11:
12: /**
13: * A naive implementation of {@link IC4Solution}.
14: */
15: public class C4SolutionHeavy implements IC4Solution {
16:
17: /**
18: * The player who placed the solution.
19: */
20: private final IC4Player owner;
21:
22: /**
23: * The start position of the solution.
24: */
25: private final IC4Position startPosition;
26:
27: /**
28: * The end position of the solution.
29: */
30: private final IC4Position endPosition;
31:
32: /**
33: * The direction of the solution.
34: */
35: private final C4Direction direction;
36:
37: /**
38: * The fields in which the solution is contained.
39: */
40: private final IC4Field[] containingFields;
41:
42: /**
43: * Creates a new solution.
44: *
45: * @param owner The player who placed the solution.
46: * @param startPosition The start position of the solution.
47: * @param endPosition The end position of the solution.
48: * @param direction The direction of the solution.
49: * @param containingFields The fields in which the solution is contained.
50: */
51: public C4SolutionHeavy(final IC4Player owner, final IC4Position startPosition,
52: final IC4Position endPosition, final C4Direction direction,
53: final IC4Field... containingFields) {
54: this.owner = owner;
55: this.startPosition = startPosition;
56: this.endPosition = endPosition;
57: this.direction = direction;
58: this.containingFields = Arrays.copyOf(containingFields, containingFields.length);
59: }
60:
61: @Override
62: public IC4Player getOwner() {
63: return this.owner;
64: }
65:
66: @Override
67: public IC4Position getStartPosition() {
68: return this.startPosition;
69: }
70:
71: @Override
72: public IC4Position getEndPosition() {
73: return this.endPosition;
74: }
75:
76: @Override
77: public C4Direction getDirection() {
78: return this.direction;
79: }
80:
81: @Override
82: public int size() {
83: return this.containingFields.length;
84: }
85:
86: @Override
87: public IC4Field[] getContainingFields() {
88: return Arrays.copyOf(this.containingFields, this.containingFields.length);
89: }
90:
91: @Override
92: public boolean equals(final Object other) {
93:• if (other == null) {
94: return false;
95: }
96:• if (!(other instanceof IC4SolutionSlim)) {
97: return false;
98: }
99: final IC4SolutionSlim otherSolution = (IC4SolutionSlim) other;
100:• return this.getOwner().equals(otherSolution.getOwner())
101: // we don't care what direction a solution is facing.
102: // the direction itself should probably be internal, but I guess
103: // it may have valid use cases for consumers of our library :)
104:• && (this.getStartPosition().equals(otherSolution.getStartPosition())
105:• && this.getEndPosition().equals(otherSolution.getEndPosition())
106:• || this.getStartPosition().equals(otherSolution.getEndPosition())
107:• && this.getEndPosition().equals(otherSolution.getStartPosition()))
108:• && this.size() == otherSolution.size();
109: }
110:
111: @Override
112: public int hashCode() {
113: int hash = 7 * 31;
114: hash += this.getOwner().hashCode();
115: hash = hash * 31 + (this.getStartPosition().hashCode() ^ this.getEndPosition().hashCode());
116: hash = hash * 31 + this.size();
117: return hash;
118: }
119:
120: @Override
121: public String toString() {
122: return String.format("C4SolutionSlim: (%d, %d) -- %d -- (%d, %d)",
123: this.getStartPosition().getRow(), this.getStartPosition().getColumn(),
124: this.getOwner().getToken(), this.getEndPosition().getRow(), this.getEndPosition().getColumn());
125: }
126: }