aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-01 18:36:32 +0100
committerPacien TRAN-GIRARD2016-03-01 18:38:02 +0100
commite80fc8044f9628c4d8d246eb764cb83a64f8d5dc (patch)
tree12ecb86ec1aa68cfb74d6ff4da5dfab50f8c9ac9
parenta111835984e2d6abbf3dcab317cf97c0f5842ba1 (diff)
downloadxblast-e80fc8044f9628c4d8d246eb764cb83a64f8d5dc.tar.gz
Automatic code cleanup
-rw-r--r--src/ch/epfl/xblast/server/Board.java37
-rw-r--r--test/ch/epfl/xblast/server/BoardTest.java31
2 files changed, 30 insertions, 38 deletions
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java
index 4d2e743..5e03671 100644
--- a/src/ch/epfl/xblast/server/Board.java
+++ b/src/ch/epfl/xblast/server/Board.java
@@ -32,15 +32,12 @@ public final class Board {
32 * @throws IllegalArgumentException if the matrix does not comply with the given sizes. 32 * @throws IllegalArgumentException if the matrix does not comply with the given sizes.
33 */ 33 */
34 private static void checkBlockMatrix(List<List<Block>> matrix, int rows, int columns) { 34 private static void checkBlockMatrix(List<List<Block>> matrix, int rows, int columns) {
35 if (matrix.size() != rows) { 35 if (matrix == null || matrix.size() != rows)
36 throw new IllegalArgumentException(); 36 throw new IllegalArgumentException();
37 } else { 37
38 for (int i = 0; i < rows; i++) { 38 for (int i = 0; i < rows; i++)
39 if (matrix.get(i).size() != columns) { 39 if (matrix.get(i).size() != columns)
40 throw new IllegalArgumentException(); 40 throw new IllegalArgumentException();
41 }
42 }
43 }
44 } 41 }
45 42
46 /** 43 /**
@@ -55,9 +52,9 @@ public final class Board {
55 * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements 52 * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements
56 */ 53 */
57 public Board(List<Sq<Block>> blocks) { 54 public Board(List<Sq<Block>> blocks) {
58 if (blocks.size() != BLOCKS_LIST_SIZE) { 55 if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE)
59 throw new IllegalArgumentException(); 56 throw new IllegalArgumentException();
60 } 57
61 this.blocks = blocks; 58 this.blocks = blocks;
62 } 59 }
63 60
@@ -72,11 +69,9 @@ public final class Board {
72 checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS); 69 checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS);
73 List<Sq<Block>> blocksSequence = new ArrayList<>(); 70 List<Sq<Block>> blocksSequence = new ArrayList<>();
74 71
75 for (int i = 0; i < rows.size(); i++) { 72 for (List<Block> row : rows)
76 for (int j = 0; j < rows.get(i).size(); j++) { 73 for (Block aRow : row)
77 blocksSequence.add(Sq.constant(rows.get(i).get(j))); 74 blocksSequence.add(Sq.constant(aRow));
78 }
79 }
80 75
81 return new Board(blocksSequence); 76 return new Board(blocksSequence);
82 } 77 }
@@ -93,12 +88,10 @@ public final class Board {
93 List<List<Block>> rowsList = new ArrayList<>(); 88 List<List<Block>> rowsList = new ArrayList<>();
94 List<Block> wallLine = new ArrayList<>(); 89 List<Block> wallLine = new ArrayList<>();
95 90
96 for (int i = 0; i < BOARD_COLUMNS; i++) { 91 for (int i = 0; i < BOARD_COLUMNS; i++)
97 wallLine.add(Block.INDESTRUCTIBLE_WALL); 92 wallLine.add(Block.INDESTRUCTIBLE_WALL);
98 }
99 93
100 for (int i = 0; i < innerBlocks.size(); i++) { 94 for (List<Block> row : innerBlocks) {
101 List<Block> row = innerBlocks.get(i);
102 row.add(0, Block.INDESTRUCTIBLE_WALL); 95 row.add(0, Block.INDESTRUCTIBLE_WALL);
103 row.add(Block.INDESTRUCTIBLE_WALL); 96 row.add(Block.INDESTRUCTIBLE_WALL);
104 97
@@ -123,9 +116,9 @@ public final class Board {
123 List<List<Block>> rowsList = new ArrayList<>(); 116 List<List<Block>> rowsList = new ArrayList<>();
124 List<List<Block>> halfInnerBoard = Lists.mirrored(quadrantNWBlocks); 117 List<List<Block>> halfInnerBoard = Lists.mirrored(quadrantNWBlocks);
125 118
126 for (int i = 0; i < halfInnerBoard.size(); i++) { 119 for (List<Block> aHalfInnerBoard : halfInnerBoard)
127 rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); 120 rowsList.add(Lists.mirrored(aHalfInnerBoard));
128 } 121
129 return ofInnerBlocksWalled(rowsList); 122 return ofInnerBlocksWalled(rowsList);
130 } 123 }
131 124
diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java
index 5cf2aef..014bd17 100644
--- a/test/ch/epfl/xblast/server/BoardTest.java
+++ b/test/ch/epfl/xblast/server/BoardTest.java
@@ -26,9 +26,8 @@ public class BoardTest {
26 public void isBoardBuilderIllegalInputThrowingException() { 26 public void isBoardBuilderIllegalInputThrowingException() {
27 List<Sq<Block>> blocks = new ArrayList<>(); 27 List<Sq<Block>> blocks = new ArrayList<>();
28 28
29 for (int i = 0; i < 8; i++) { 29 for (int i = 0; i < 8; i++)
30 blocks.add(Sq.constant(Block.FREE)); 30 blocks.add(Sq.constant(Block.FREE));
31 }
32 31
33 new Board(blocks); 32 new Board(blocks);
34 } 33 }
@@ -44,9 +43,9 @@ public class BoardTest {
44 List<List<Block>> rowsList = new ArrayList<>(); 43 List<List<Block>> rowsList = new ArrayList<>();
45 List<Block> sampleRow = new ArrayList<>(); 44 List<Block> sampleRow = new ArrayList<>();
46 45
47 for (int i = 0; i < 8; i++) { 46 for (int i = 0; i < 8; i++)
48 sampleRow.add(Block.FREE); 47 sampleRow.add(Block.FREE);
49 } 48
50 rowsList.add(sampleRow); 49 rowsList.add(sampleRow);
51 50
52 assertTrue(Board.ofRows(rowsList) instanceof Board); 51 assertTrue(Board.ofRows(rowsList) instanceof Board);
@@ -58,9 +57,9 @@ public class BoardTest {
58 57
59 for (int i = 0; i < 13; i++) { 58 for (int i = 0; i < 13; i++) {
60 List<Block> sampleRow = new ArrayList<>(); 59 List<Block> sampleRow = new ArrayList<>();
61 for (int j = 0; j < 15; j++) { 60 for (int j = 0; j < 15; j++)
62 sampleRow.add(Block.FREE); 61 sampleRow.add(Block.FREE);
63 } 62
64 rowsList.add(sampleRow); 63 rowsList.add(sampleRow);
65 } 64 }
66 65
@@ -78,9 +77,9 @@ public class BoardTest {
78 List<List<Block>> rowsList = new ArrayList<>(); 77 List<List<Block>> rowsList = new ArrayList<>();
79 List<Block> sampleRow = new ArrayList<>(); 78 List<Block> sampleRow = new ArrayList<>();
80 79
81 for (int i = 0; i < 8; i++) { 80 for (int i = 0; i < 8; i++)
82 sampleRow.add(Block.FREE); 81 sampleRow.add(Block.FREE);
83 } 82
84 rowsList.add(sampleRow); 83 rowsList.add(sampleRow);
85 84
86 assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); 85 assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board);
@@ -92,9 +91,9 @@ public class BoardTest {
92 91
93 for (int i = 0; i < 11; i++) { 92 for (int i = 0; i < 11; i++) {
94 List<Block> sampleRow = new ArrayList<>(); 93 List<Block> sampleRow = new ArrayList<>();
95 for (int j = 0; j < 13; j++) { 94 for (int j = 0; j < 13; j++)
96 sampleRow.add(Block.FREE); 95 sampleRow.add(Block.FREE);
97 } 96
98 rowsList.add(sampleRow); 97 rowsList.add(sampleRow);
99 } 98 }
100 99
@@ -112,9 +111,9 @@ public class BoardTest {
112 List<List<Block>> rowsList = new ArrayList<>(); 111 List<List<Block>> rowsList = new ArrayList<>();
113 List<Block> sampleRow = new ArrayList<>(); 112 List<Block> sampleRow = new ArrayList<>();
114 113
115 for (int i = 0; i < 8; i++) { 114 for (int i = 0; i < 8; i++)
116 sampleRow.add(Block.FREE); 115 sampleRow.add(Block.FREE);
117 } 116
118 rowsList.add(sampleRow); 117 rowsList.add(sampleRow);
119 118
120 assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); 119 assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board);
@@ -126,9 +125,9 @@ public class BoardTest {
126 125
127 for (int i = 0; i < 6; i++) { 126 for (int i = 0; i < 6; i++) {
128 List<Block> sampleRow = new ArrayList<>(); 127 List<Block> sampleRow = new ArrayList<>();
129 for (int j = 0; j < 7; j++) { 128 for (int j = 0; j < 7; j++)
130 sampleRow.add(Block.FREE); 129 sampleRow.add(Block.FREE);
131 } 130
132 rowsList.add(sampleRow); 131 rowsList.add(sampleRow);
133 } 132 }
134 133
@@ -143,9 +142,9 @@ public class BoardTest {
143 List<Sq<Block>> blocksList = new ArrayList<>(); 142 List<Sq<Block>> blocksList = new ArrayList<>();
144 143
145 blocksList.add(Sq.constant(Block.INDESTRUCTIBLE_WALL)); 144 blocksList.add(Sq.constant(Block.INDESTRUCTIBLE_WALL));
146 for (int i = 0; i < 194; i++) { 145 for (int i = 0; i < 194; i++)
147 blocksList.add(Sq.constant(Block.FREE)); 146 blocksList.add(Sq.constant(Block.FREE));
148 } 147
149 Board sampleBoard = new Board(blocksList); 148 Board sampleBoard = new Board(blocksList);
150 149
151 assertTrue(sampleBoard.blockAt(sampleCell) == Block.INDESTRUCTIBLE_WALL); 150 assertTrue(sampleBoard.blockAt(sampleCell) == Block.INDESTRUCTIBLE_WALL);