From b632e590f94dbef1a4415100456528772f7014f8 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Thu, 17 Nov 2016 21:36:21 -0500 Subject: Create tabbed view --- src/com/benburwell/planes/data/AircraftStore.java | 34 ++++++++++++++++++++++ .../planes/data/AircraftStoreListener.java | 9 ++++++ 2 files changed, 43 insertions(+) create mode 100644 src/com/benburwell/planes/data/AircraftStore.java create mode 100644 src/com/benburwell/planes/data/AircraftStoreListener.java (limited to 'src/com/benburwell/planes/data') 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 aircraftMap = new HashMap<>(); + private List aircraftListeners = new ArrayList<>(); + + public Map 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); +} -- cgit v1.2.3