diff --git a/src/main/java/model/Cell.java b/src/main/java/model/Cell.java index 03780346a5a4b46bb5c2b61d704ec27ee00bef63..a7d53ca4b95422ccd9d4417de3a9d7f267f2c5b9 100644 --- a/src/main/java/model/Cell.java +++ b/src/main/java/model/Cell.java @@ -13,7 +13,7 @@ import java.util.List; */ public class Cell<T> implements Lens<T> { - //TODO: ajouter la ou les propriétés nécessaires + private T content; // la liste des objets écoutant les modifications du contenu de la cellule private final List<OnChangeListener<T>> listeners = new ArrayList<>(); @@ -23,7 +23,7 @@ public class Cell<T> implements Lens<T> { * @param initialContent the value initially stored by the cell. */ public Cell(T initialContent) { - //TODO: à compléter + this.content = initialContent; } /** Add a {@link OnChangeListener} to react to any change of value in the cell. @@ -42,8 +42,11 @@ 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 = this.content; + this.content = value; + for (OnChangeListener<T> listener : this.listeners) { + listener.valueChanged(oldValue,value); + } } /** @@ -52,7 +55,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 this.content; } }