package model; /** * A single observed data that notifies the observer once changed. */ public class ObservedData { /** * The data. */ private T data; /** * The observer. */ private Observer acceptor; /** * EFFECTS: Init with the given initial value and observer. * REQUIRES: acceptor != null */ public ObservedData(T initialValue, Observer acceptor) { this.data = initialValue; this.acceptor = acceptor; } /** * EFFECTS: Set the data and notify the observer with the new data and DIRECTION_CHANGE + INDEX_NOT_IN_LIST. */ public void set(T data) { this.data = data; acceptor.accept(data, Observer.DIRECTION_CHANGE, Observer.INDEX_NOT_IN_LIST); } /** * EFFECTS: Get the data. */ public T get() { return data; } /** * EFFECTS: Get the observer. */ public Observer getAcceptor() { return acceptor; } }