From 620db9c5e948b5c282dc9d33a24fe2e926cd4ce4 Mon Sep 17 00:00:00 2001 From: Guyslain <guyslain.naves@lis-lab.fr> Date: Mon, 23 Oct 2023 16:14:02 +0200 Subject: [PATCH] section 8 Cell fini --- src/main/java/model/Cell.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/model/Cell.java b/src/main/java/model/Cell.java index 0378034..a7d53ca 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; } } -- GitLab