From 2e2e281265e62f7621ae7094c680000edaddf64a Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 1 Feb 2018 21:00:06 +0100 Subject: Move Matrix util Signed-off-by: pacien --- src/main/java/fr/umlv/java/wallj/board/Board.java | 1 - .../java/fr/umlv/java/wallj/board/BoardParser.java | 1 - src/main/java/fr/umlv/java/wallj/board/Matrix.java | 54 +++++++++++++++++++++ src/main/java/fr/umlv/java/wallj/utils/Matrix.java | 56 ---------------------- 4 files changed, 54 insertions(+), 58 deletions(-) create mode 100644 src/main/java/fr/umlv/java/wallj/board/Matrix.java delete mode 100644 src/main/java/fr/umlv/java/wallj/utils/Matrix.java (limited to 'src/main/java/fr') diff --git a/src/main/java/fr/umlv/java/wallj/board/Board.java b/src/main/java/fr/umlv/java/wallj/board/Board.java index ad29fe6..5677c39 100644 --- a/src/main/java/fr/umlv/java/wallj/board/Board.java +++ b/src/main/java/fr/umlv/java/wallj/board/Board.java @@ -1,7 +1,6 @@ package fr.umlv.java.wallj.board; import fr.umlv.java.wallj.block.BlockType; -import fr.umlv.java.wallj.utils.Matrix; import java.util.AbstractMap; import java.util.Arrays; diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardParser.java b/src/main/java/fr/umlv/java/wallj/board/BoardParser.java index 39adda7..3b77767 100644 --- a/src/main/java/fr/umlv/java/wallj/board/BoardParser.java +++ b/src/main/java/fr/umlv/java/wallj/board/BoardParser.java @@ -1,7 +1,6 @@ package fr.umlv.java.wallj.board; import fr.umlv.java.wallj.block.BlockType; -import fr.umlv.java.wallj.utils.Matrix; import java.io.IOException; import java.nio.file.Files; diff --git a/src/main/java/fr/umlv/java/wallj/board/Matrix.java b/src/main/java/fr/umlv/java/wallj/board/Matrix.java new file mode 100644 index 0000000..c6a2528 --- /dev/null +++ b/src/main/java/fr/umlv/java/wallj/board/Matrix.java @@ -0,0 +1,54 @@ +package fr.umlv.java.wallj.board; + +import java.util.List; + +/** + * Utility functions for two dimension arrays and lists. + * + * @author Pacien TRAN-GIRARD + */ +public final class Matrix { + /** + * @param m the matrix (2D array) + * @return the width of the matrix (0 if null) + */ + public static int getWidth(Object[][] m) { + return m != null && m.length > 0 ? m[0].length : 0; + } + + /** + * @param m the matrix (2D array) + * @return the height of the matrix (0 if null) + */ + public static int getHeight(Object[][] m) { + return m != null ? m.length : 0; + } + + /** + * @param m the matrix (2D List) + * @return the width of the matrix (0 if null) + */ + public static int getWidth(List> m) { + return m != null && m.size() > 0 ? m.get(0).size() : 0; + } + + /** + * @param m the matrix (2D List) + * @return the height of the matrix (0 if null) + */ + public static int getHeight(List> m) { + return m != null ? m.size() : 0; + } + + /** + * @param l the 2D list to check + * @return T(l is a valid matrix, i.e. all sub - arrays are of the same size and l is not null) + */ + public static boolean isShapeValid(List> l) { + return l != null && l.stream().mapToInt(List::size).allMatch(s -> s == l.get(0).size()); + } + + private Matrix() { + // static class + } +} diff --git a/src/main/java/fr/umlv/java/wallj/utils/Matrix.java b/src/main/java/fr/umlv/java/wallj/utils/Matrix.java deleted file mode 100644 index 83dfc11..0000000 --- a/src/main/java/fr/umlv/java/wallj/utils/Matrix.java +++ /dev/null @@ -1,56 +0,0 @@ -package fr.umlv.java.wallj.utils; - -import java.util.List; - -/** - * Utility functions for two dimension arrays and lists. - * - * @author Pacien TRAN-GIRARD - */ -public final class Matrix { - - /** - * @param m the matrix (2D array) - * @return the width of the matrix (0 if null) - */ - public static int getWidth(Object[][] m) { - return m != null && m.length > 0 ? m[0].length : 0; - } - - /** - * @param m the matrix (2D array) - * @return the height of the matrix (0 if null) - */ - public static int getHeight(Object[][] m) { - return m != null ? m.length : 0; - } - - /** - * @param m the matrix (2D List) - * @return the width of the matrix (0 if null) - */ - public static int getWidth(List> m) { - return m != null && m.size() > 0 ? m.get(0).size() : 0; - } - - /** - * @param m the matrix (2D List) - * @return the height of the matrix (0 if null) - */ - public static int getHeight(List> m) { - return m != null ? m.size() : 0; - } - - /** - * @param l the 2D list to check - * @return T(l is a valid matrix, i.e. all sub - arrays are of the same size and l is not null) - */ - public static boolean isShapeValid(List> l) { - return l != null && l.stream().mapToInt(List::size).allMatch(s -> s == l.get(0).size()); - } - - private Matrix() { - // static class - } - -} -- cgit v1.2.3