Skip to content

Package: ViergewinntRowImpl

ViergewinntRowImpl

nameinstructionbranchcomplexitylinemethod
ViergewinntRowImpl(Integer, Integer, VierGewinntBoard)
M: 0 C: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
ViergewinntRowImpl(ViergewinntRowImpl, VierGewinntBoard)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
deepCopy(VierGewinntBoard)
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%
equals(Object)
M: 2 C: 40
95%
M: 3 C: 9
75%
M: 3 C: 4
57%
M: 1 C: 10
91%
M: 0 C: 1
100%
getFields()
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: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$0(VierGewinntBoard, VierGewinntField)
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%
lambda$toString$1(VierGewinntField, VierGewinntField)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 33 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package de.fhdw.gaming.ipspiel21.viergewinnt.core.domain.impl;
2:
3: import java.util.ArrayList;
4: import java.util.Iterator;
5: import java.util.List;
6: import java.util.stream.Collectors;
7:
8: import de.fhdw.gaming.core.domain.GameException;
9: import de.fhdw.gaming.ipspiel21.viergewinnt.core.domain.VierGewinntBoard;
10: import de.fhdw.gaming.ipspiel21.viergewinnt.core.domain.VierGewinntField;
11: import de.fhdw.gaming.ipspiel21.viergewinnt.core.domain.VierGewinntPosition;
12: import de.fhdw.gaming.ipspiel21.viergewinnt.core.domain.VierGewinntRow;
13:
14: /**
15: * Implementation of a Row in a VierGewinntGame.
16: *
17: * @author Robby Rabbitman
18: *
19: */
20: public class ViergewinntRowImpl implements VierGewinntRow {
21:
22: /**
23: * fields of this row.
24: *
25: */
26: private final List<VierGewinntField> fields;
27:
28: /**
29: * Create row with number of fields.
30: *
31: * @param numberOfFields
32: * @param row
33: * @param board
34: * @throws GameException
35: */
36: public ViergewinntRowImpl(final Integer numberOfFields, final Integer row, final VierGewinntBoard board)
37: throws GameException {
38: super();
39: this.fields = new ArrayList<>(numberOfFields);
40:• for (int i = 0; i < numberOfFields; i++) {
41: this.fields.add(new VierGewinntFieldImpl(VierGewinntPosition.of(row, i), board));
42: }
43: }
44:
45: /**
46: * copy.
47: *
48: * @param source
49: * @param board The board to associate with this row.
50: */
51: private ViergewinntRowImpl(final ViergewinntRowImpl source, final VierGewinntBoard board) {
52: super();
53: this.fields = source.getFields().stream().map((final VierGewinntField field) -> field.deepCopy(board))
54: .collect(Collectors.toList());
55: }
56:
57: @Override
58: public List<VierGewinntField> getFields() {
59: return this.fields;
60: }
61:
62: @Override
63: public VierGewinntRow deepCopy(final VierGewinntBoard target) {
64: return new ViergewinntRowImpl(this, target);
65: }
66:
67: @Override
68: public String toString() {
69: final StringBuilder out = new StringBuilder();
70: for (final VierGewinntField field : this.fields.stream()
71: .sorted((a, b) -> a.getPosition().getColumn() - b.getPosition().getColumn())
72:• .collect(Collectors.toList())) {
73: out.append(field.getState().toString()).append(' ');
74: }
75: return out.toString();
76: }
77:
78: @Override
79: public boolean equals(final Object obj) {
80:• if (obj == null || obj.getClass() != this.getClass()) {
81: return false;
82:• } else if (obj == this) {
83: return true;
84: }
85:
86: final ViergewinntRowImpl otherRow = (ViergewinntRowImpl) obj;
87:
88: final Iterator<VierGewinntField> otherFields = otherRow.getFields().iterator();
89: final Iterator<VierGewinntField> thisFields = this.getFields().iterator();
90:
91:• while (otherFields.hasNext() && thisFields.hasNext()) {
92:• if (!(otherFields.next().equals(thisFields.next()))) {
93: return false;
94: }
95: }
96:
97: return true;
98: }
99:
100: /**
101: * Returns Hashcode of this.
102: */
103: @Override
104: public int hashCode() {
105: return this.fields.hashCode();
106: }
107: }