3815acde06a41008668a7278defcfaefc7aa4317
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / detection / AbstractClusterMatcher.java
1 package edu.uci.iotproject.detection;
2
3 import org.pcap4j.core.PcapPacket;
4
5 import java.util.List;
6 import java.util.Objects;
7
8 /**
9  * TODO add class documentation.
10  *
11  * @author Janus Varmarken
12  */
13 abstract public class AbstractClusterMatcher {
14
15     protected final List<List<PcapPacket>> mCluster;
16
17
18     protected AbstractClusterMatcher(List<List<PcapPacket>> cluster) {
19         // ===================== PRECONDITION SECTION =====================
20         cluster = Objects.requireNonNull(cluster, "cluster cannot be null");
21         if (cluster.isEmpty() || cluster.stream().anyMatch(inner -> inner.isEmpty())) {
22             throw new IllegalArgumentException("cluster is empty (or contains an empty inner List)");
23         }
24         mCluster = pruneCluster(cluster);
25     }
26
27     /**
28      * Allows subclasses to specify how to prune input cluster provided to the constructor.
29      * @param cluster The input cluster provided to the constructor.
30      * @return The pruned cluster to use in place of the input cluster.
31      */
32     abstract protected List<List<PcapPacket>> pruneCluster(List<List<PcapPacket>> cluster);
33
34     // TODO: move Direction outside Conversation so that this is less confusing.
35 //    abstract protected Conversation.Direction[] getPacketDirections(List<PcapPacket> packets);
36
37 }