From f8bfd13e08821e6c10efe1d4f8d202ad033b30e4 Mon Sep 17 00:00:00 2001 From: s23026062 <melis-damla.sahin@etu.univ-amu.fr> Date: Tue, 26 Nov 2024 15:51:58 +0100 Subject: [PATCH] =?UTF-8?q?Compl=C3=A9ter=20la=20classe=20Cell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/Cell.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/model/Cell.java b/src/main/java/model/Cell.java index f7f6274..1c28094 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; } } -- GitLab