X-Git-Url: http://plrg.eecs.uci.edu/git/?p=pingpong.git;a=blobdiff_plain;f=Code%2FProjects%2FSmartPlugDetector%2Fsrc%2Fmain%2Fjava%2Fedu%2Fuci%2Fiotproject%2Fdetection%2FAbstractClusterMatcher.java;fp=Code%2FProjects%2FSmartPlugDetector%2Fsrc%2Fmain%2Fjava%2Fedu%2Fuci%2Fiotproject%2Fdetection%2FAbstractClusterMatcher.java;h=45c6a55ef86dd23757a0dad1c66c93590cbccb5a;hp=bda6493cb04978f2eafc178ff27d15b27821871e;hb=f70c5ce52c1712c6c733fec2de1ba976b041ef16;hpb=345c032d3f6e80a4a56bb68caadecf54ff500245 diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/AbstractClusterMatcher.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/AbstractClusterMatcher.java index bda6493..45c6a55 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/AbstractClusterMatcher.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/AbstractClusterMatcher.java @@ -2,6 +2,7 @@ package edu.uci.iotproject.detection; import org.pcap4j.core.PcapPacket; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -20,6 +21,11 @@ abstract public class AbstractClusterMatcher { */ protected final List> mCluster; + /** + * Observers registered for callbacks from this {@link AbstractClusterMatcher}. + */ + protected final List mObservers; + protected AbstractClusterMatcher(List> cluster) { // ===================== PRECONDITION SECTION ===================== cluster = Objects.requireNonNull(cluster, "cluster cannot be null"); @@ -34,6 +40,23 @@ abstract public class AbstractClusterMatcher { // ================================================================ // Let the subclass prune the provided cluster mCluster = pruneCluster(cluster); + mObservers = new ArrayList<>(); + } + + /** + * Register for callbacks from this cluster matcher. + * @param observer The target of the callbacks. + */ + public final void addObserver(ClusterMatcherObserver observer) { + mObservers.add(observer); + } + + /** + * Deregister for callbacks from this cluster matcher. + * @param observer The callback target that is to be deregistered. + */ + public final void removeObserver(ClusterMatcherObserver observer) { + mObservers.remove(observer); } /**