From e80fc8044f9628c4d8d246eb764cb83a64f8d5dc Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 1 Mar 2016 18:36:32 +0100 Subject: Automatic code cleanup --- src/ch/epfl/xblast/server/Board.java | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'src/ch/epfl') 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 { * @throws IllegalArgumentException if the matrix does not comply with the given sizes. */ private static void checkBlockMatrix(List> matrix, int rows, int columns) { - if (matrix.size() != rows) { + if (matrix == null || matrix.size() != rows) throw new IllegalArgumentException(); - } else { - for (int i = 0; i < rows; i++) { - if (matrix.get(i).size() != columns) { - throw new IllegalArgumentException(); - } - } - } + + for (int i = 0; i < rows; i++) + if (matrix.get(i).size() != columns) + throw new IllegalArgumentException(); } /** @@ -55,9 +52,9 @@ public final class Board { * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements */ public Board(List> blocks) { - if (blocks.size() != BLOCKS_LIST_SIZE) { + if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE) throw new IllegalArgumentException(); - } + this.blocks = blocks; } @@ -72,11 +69,9 @@ public final class Board { checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS); List> blocksSequence = new ArrayList<>(); - for (int i = 0; i < rows.size(); i++) { - for (int j = 0; j < rows.get(i).size(); j++) { - blocksSequence.add(Sq.constant(rows.get(i).get(j))); - } - } + for (List row : rows) + for (Block aRow : row) + blocksSequence.add(Sq.constant(aRow)); return new Board(blocksSequence); } @@ -93,12 +88,10 @@ public final class Board { List> rowsList = new ArrayList<>(); List wallLine = new ArrayList<>(); - for (int i = 0; i < BOARD_COLUMNS; i++) { + for (int i = 0; i < BOARD_COLUMNS; i++) wallLine.add(Block.INDESTRUCTIBLE_WALL); - } - for (int i = 0; i < innerBlocks.size(); i++) { - List row = innerBlocks.get(i); + for (List row : innerBlocks) { row.add(0, Block.INDESTRUCTIBLE_WALL); row.add(Block.INDESTRUCTIBLE_WALL); @@ -123,9 +116,9 @@ public final class Board { List> rowsList = new ArrayList<>(); List> halfInnerBoard = Lists.mirrored(quadrantNWBlocks); - for (int i = 0; i < halfInnerBoard.size(); i++) { - rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); - } + for (List aHalfInnerBoard : halfInnerBoard) + rowsList.add(Lists.mirrored(aHalfInnerBoard)); + return ofInnerBlocksWalled(rowsList); } -- cgit v1.2.3