diff --git a/src/main/java/matrix/ListMatrix.java b/src/main/java/matrix/ListMatrix.java index a3a4e7d562c43dded22737a89919f85f5eca6040..0e9bf482389a0ec273d8a72262ceb6e879b7805a 100644 --- a/src/main/java/matrix/ListMatrix.java +++ b/src/main/java/matrix/ListMatrix.java @@ -1,5 +1,6 @@ package matrix; +import java.util.ArrayList; import java.util.List; @@ -23,10 +24,9 @@ public class ListMatrix<T> implements Matrix<T> { * @param initializer A matrix initializer to set values in the {@link ListMatrix}. */ public ListMatrix(int width, int height, MatrixInitializer<T> initializer) { - // TODO - this.width = 0; - this.height = 0; - this.matrix = null; + this.width = width; + this.height = height; + this.matrix = new ArrayList<>(width); this.initializeWith(initializer); // fills the matrix using initializer } @@ -35,29 +35,33 @@ public class ListMatrix<T> implements Matrix<T> { } private void initializeWith(MatrixInitializer<T> initializer) { - // TODO initialize each cell of the matrix, with a value determined by initializer + for (int x=0; x<width; x++) { + List<T> column = new ArrayList<>(height); + for (int y=0; y<height; y++) { + column.add(initializer.initialValueAt(new Coordinate(x, y))); + } + matrix.add(column); + } + } public int width() { - // TODO - return 0; + return width; } public int height() { - // TODO - return 0; + return height; } @Override - public T get(int x, int y) { - // TODO - return null; + public T get(int x, int y) { // une liste de listes + return matrix.get(x).get(y); } @Override public void set(int x, int y, T newValue) { - // TODO + matrix.get(x).set(y,newValue); } }