Skip to content
Snippets Groups Projects
Commit ede6cf57 authored by hiba1907's avatar hiba1907
Browse files

Realisation de l'ajout de la ethode statique count dans l'interface State

parent 5dfb7bfa
No related branches found
No related tags found
No related merge requests found
Pipeline #40395 failed
Showing
with 32 additions and 20 deletions
No preview for this file type
No preview for this file type
No preview for this file type
File added
File deleted
File added
File added
File deleted
File added
File added
No preview for this file type
File added
No preview for this file type
package matrix; package matrix;
import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -23,41 +24,47 @@ public class ListMatrix<T> implements Matrix<T> { ...@@ -23,41 +24,47 @@ 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 = width;
this.width = 0; this.height = height;
this.height = 0; this.matrix = new ArrayList<>(width);
this.matrix = null; // fills the matrix using initializer
this.initializeWith(initializer); // fills the matrix using initializer for(int x =0;x<width;x++){
List<T> row = new ArrayList<>(height);
for(int y = 0;y<height;y++){
row.add(initializer.initialValueAt(new Coordinate(x,y)));
}
matrix.add(row);
} }
public ListMatrix(int width, int height, T constant) {
this(width, height, new ConstantMatrixInitializer<>(constant));
} }
private void initializeWith(MatrixInitializer<T> initializer) { public ListMatrix(int width, int height, T constant) {
// TODO initialize each cell of the matrix, with a value determined by initializer this(width, height, coord->constant);
} }
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 checkBounds(x,y);
return null; return matrix.get(y).get(x);
} }
@Override @Override
public void set(int x, int y, T newValue) { public void set(int x, int y, T newValue) {
// TODO checkBounds(x,y);
matrix.get(y).set(x,newValue);
} }
private void checkBounds(int x, int y){
if(x<0|| x>=width ||y<0||y>= height){
throw new IndexOutOfBoundsException("Indicces out of bounds;("+x+","+")");
}
}
} }
...@@ -44,7 +44,12 @@ public interface State<S> { ...@@ -44,7 +44,12 @@ public interface State<S> {
* @return The number of times the specified state appears in the list of neighbors. * @return The number of times the specified state appears in the list of neighbors.
*/ */
static <T> int count(T state, List<T> neighbours) { static <T> int count(T state, List<T> neighbours) {
//TODO: à compléter int count =0;
return 0; for(T voisin: neighbours){
if (voisin.equals(state)){
count ++;
}
}
return count;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment