Skip to content
Snippets Groups Projects
Commit 538d361d authored by POUSSARDIN Malo's avatar POUSSARDIN Malo
Browse files

fin tp6

parent fb1d1cf7
No related branches found
No related tags found
No related merge requests found
Pipeline #40508 failed
...@@ -2,15 +2,14 @@ package matrix; ...@@ -2,15 +2,14 @@ package matrix;
public class ConstantMatrixInitializer<T> implements MatrixInitializer<T> { public class ConstantMatrixInitializer<T> implements MatrixInitializer<T> {
// TODO: add instance variables private final T value;
public ConstantMatrixInitializer(T constant) { public ConstantMatrixInitializer(T constant) {
// TODO this.value = constant;
} }
@Override @Override
public T initialValueAt(Coordinate coordinate) { public T initialValueAt(Coordinate coordinate) {
// TODO return value;
return null;
} }
} }
package matrix; package matrix;
import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -23,11 +24,19 @@ public class ListMatrix<T> implements Matrix<T> { ...@@ -23,11 +24,19 @@ public class ListMatrix<T> implements Matrix<T> {
* @param initializer A matrix initializer to set values in the {@link ListMatrix}. * @param initializer A matrix initializer to set values in the {@link ListMatrix}.
*/ */
public ListMatrix(int width, int height, MatrixInitializer<T> initializer) { public ListMatrix(int width, int height, MatrixInitializer<T> initializer) {
// TODO
this.width = 0; this.width = 0;
this.height = 0; this.height = 0;
this.matrix = null; this.matrix = null;
this.initializeWith(initializer); // fills the matrix using initializer this.initializeWith(initializer);
for (int i = 0; i < height; i++) {
List<T> row = new ArrayList<>(width);
for (int j = 0; j < width; j++) {
row.add(null);
}
matrix.add(row);
}
this.initializeWith(initializer);
} }
public ListMatrix(int width, int height, T constant) { public ListMatrix(int width, int height, T constant) {
...@@ -35,29 +44,30 @@ public class ListMatrix<T> implements Matrix<T> { ...@@ -35,29 +44,30 @@ public class ListMatrix<T> implements Matrix<T> {
} }
private void initializeWith(MatrixInitializer<T> initializer) { private void initializeWith(MatrixInitializer<T> initializer) {
// TODO initialize each cell of the matrix, with a value determined by initializer for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix.get(i).size(); j++) {
matrix.get(i).set(j, initializer.initialValueAt(Coordinate.of(i,j)));
}
}
} }
public int width() { public int width() {
// TODO return width;
return 0;
} }
public int height() { public int height() {
// TODO return height;
return 0;
} }
@Override @Override
public T get(int x, int y) { public T get(int x, int y) {
// TODO return matrix.get(x).get(y);
return null;
} }
@Override @Override
public void set(int x, int y, T newValue) { public void set(int x, int y, T newValue) {
// TODO matrix.get(x).set(y, newValue);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment