summaryrefslogtreecommitdiff
path: root/src/com/benburwell/planes/data
diff options
context:
space:
mode:
authorBen Burwell <ben.burwell@trifecta.com>2016-11-17 21:36:21 -0500
committerBen Burwell <ben.burwell@trifecta.com>2016-11-17 21:36:21 -0500
commitb632e590f94dbef1a4415100456528772f7014f8 (patch)
tree100202b97b0fd2953e9bf6499e961bb333b32cfe /src/com/benburwell/planes/data
parentce6c853650b491fbd21170b29ad7f70f578d6829 (diff)
Create tabbed view
Diffstat (limited to 'src/com/benburwell/planes/data')
-rw-r--r--src/com/benburwell/planes/data/AircraftStore.java34
-rw-r--r--src/com/benburwell/planes/data/AircraftStoreListener.java9
2 files changed, 43 insertions, 0 deletions
diff --git a/src/com/benburwell/planes/data/AircraftStore.java b/src/com/benburwell/planes/data/AircraftStore.java
new file mode 100644
index 0000000..076701d
--- /dev/null
+++ b/src/com/benburwell/planes/data/AircraftStore.java
@@ -0,0 +1,34 @@
+package com.benburwell.planes.data;
+
+import com.benburwell.planes.sbs.SBSPacket;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Created by ben on 11/17/16.
+ */
+public class AircraftStore {
+ private Map<String,Aircraft> aircraftMap = new HashMap<>();
+ private List<AircraftStoreListener> aircraftListeners = new ArrayList<>();
+
+ public Map<String,Aircraft> getAircraft() {
+ return this.aircraftMap;
+ }
+
+ public void addPacket(SBSPacket packet) {
+ if (!this.aircraftMap.containsKey(packet.getHexIdent())) {
+ this.aircraftMap.put(packet.getHexIdent(), new Aircraft(packet.getHexIdent()));
+ }
+ this.aircraftMap.get(packet.getHexIdent()).handleUpdate(packet);
+ this.aircraftListeners.stream()
+ .filter(listener -> listener.respondTo(packet.getHexIdent()))
+ .forEach(AircraftStoreListener::aircraftStoreChanged);
+ }
+
+ public void subscribe(AircraftStoreListener listener) {
+ this.aircraftListeners.add(listener);
+ }
+}
diff --git a/src/com/benburwell/planes/data/AircraftStoreListener.java b/src/com/benburwell/planes/data/AircraftStoreListener.java
new file mode 100644
index 0000000..2ef635f
--- /dev/null
+++ b/src/com/benburwell/planes/data/AircraftStoreListener.java
@@ -0,0 +1,9 @@
+package com.benburwell.planes.data;
+
+/**
+ * Created by ben on 11/17/16.
+ */
+public interface AircraftStoreListener {
+ void aircraftStoreChanged();
+ boolean respondTo(String aircraftId);
+}