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