aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/Observer.java
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@student.cs.ubc.ca>2023-11-23 08:09:01 +0800
committerYuuta Liang <yuutaw@student.cs.ubc.ca>2023-11-23 08:09:01 +0800
commit65ea6c17a0c1348aa9ef4e158102ddf173936882 (patch)
tree7615366f76b6c94f46d8039aa20091f9ccd5609a /src/main/model/Observer.java
parentb94b18c133f06cb176d8aa8bb40a8e24918d9ed6 (diff)
downloadjca-65ea6c17a0c1348aa9ef4e158102ddf173936882.tar
jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.tar.gz
jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.tar.bz2
jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.zip
Add GUI
Signed-off-by: Yuuta Liang <yuutaw@student.cs.ubc.ca>
Diffstat (limited to 'src/main/model/Observer.java')
-rw-r--r--src/main/model/Observer.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/model/Observer.java b/src/main/model/Observer.java
new file mode 100644
index 0000000..df9cbc2
--- /dev/null
+++ b/src/main/model/Observer.java
@@ -0,0 +1,33 @@
+package model;
+
+/**
+ * Data observers for GUI data binding.
+ */
+@FunctionalInterface
+public interface Observer<T> {
+ /**
+ * The data is just added to a list. Index will be its index.
+ */
+ int DIRECTION_ADD = 0;
+
+ /**
+ * The data is just removed from a list. Index will be its previous index.
+ */
+ int DIRECTION_REMOVE = 1;
+
+ /**
+ * The data is modified, either or not in a list. Index will be either INDEX_NOT_IN_LIST or its index.
+ */
+ int DIRECTION_CHANGE = 2;
+
+ /**
+ * A special index representing that the data is not in a list.
+ */
+ int INDEX_NOT_IN_LIST = -1;
+
+ /**
+ * EFFECTS: Handle data change.
+ * REQUIRES: data != null, direction be DIRECTION_*, index >= 0 or == INDEX_NOT_IN_LIST.
+ */
+ void accept(T data, int direction, int index);
+}