diff --git a/src/main/java/model/Cell.java b/src/main/java/model/Cell.java index f7f62749df1c3193503dce5e366a671762967f21..1c280949903623fddde7252f82639317f9dfb50a 100644 --- a/src/main/java/model/Cell.java +++ b/src/main/java/model/Cell.java @@ -1,5 +1,8 @@ package model; +import model.automata.GameOfLifeAutomaton; +import model.automata.GameOfLifeState; + import java.util.ArrayList; import java.util.List; @@ -11,17 +14,16 @@ import java.util.List; */ public class Cell<T> implements Lens<T> { - //TODO: ajouter la ou les propriétés nécessaires - // la liste des objets écoutant les modifications du contenu de la cellule private final List<OnChangeListener<T>> listeners = new ArrayList<>(); + private T initialContent; /** Initialize a new cell with a given value. * * @param initialContent the value initially stored by the cell. */ public Cell(T initialContent) { - //TODO: à compléter + this.initialContent = initialContent; } /** Add a {@link OnChangeListener} to react to any change of value in the cell. @@ -40,8 +42,12 @@ public class Cell<T> implements Lens<T> { * @param value the new content of this {@link Cell} */ public void set(T value) { - //TODO: modifier le contenu de la cellule, puis appeler les méthodes valueChanged des - // listeners + T oldValue = initialContent; + initialContent = value; + + for (OnChangeListener<T> L : listeners) { + L.valueChanged(oldValue, value); + } } /** @@ -50,7 +56,6 @@ public class Cell<T> implements Lens<T> { * @return the current content of this {@link Cell} */ public T get(){ - //TODO: à compléter - return null; + return initialContent; } }