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;h=bda6493cb04978f2eafc178ff27d15b27821871e;hp=4c74eb86649f594555ee3bfb168dfa32f160586b;hb=1b524a7b2071d6e660164e9f1d61cb80b70ca696;hpb=4bc5b760e1f3469747793b86ac61cbd6b3b917fc 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 4c74eb8..bda6493 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 @@ -1,32 +1,43 @@ package edu.uci.iotproject.detection; -import edu.uci.iotproject.Conversation; import org.pcap4j.core.PcapPacket; import java.util.List; import java.util.Objects; /** - * TODO add class documentation. + * Base class for classes that search a traffic trace for sequences of packets that "belong to" a given cluster (in + * other words, classes that attempt to classify traffic as pertaining to a given cluster). * - * @author Janus Varmarken + * @author Janus Varmarken {@literal } + * @author Rahmadi Trimananda {@literal } */ abstract public class AbstractClusterMatcher { + /** + * The cluster that describes the sequence of packets that this {@link AbstractClusterMatcher} is trying to detect + * in the observed traffic. + */ protected final List> mCluster; - protected AbstractClusterMatcher(List> cluster) { // ===================== PRECONDITION SECTION ===================== cluster = Objects.requireNonNull(cluster, "cluster cannot be null"); if (cluster.isEmpty() || cluster.stream().anyMatch(inner -> inner.isEmpty())) { throw new IllegalArgumentException("cluster is empty (or contains an empty inner List)"); } + for (List clusterMember : cluster) { + if (clusterMember.size() != cluster.get(0).size()) { + throw new IllegalArgumentException("All sequences in cluster must contain the same number of packets"); + } + } + // ================================================================ + // Let the subclass prune the provided cluster mCluster = pruneCluster(cluster); } /** - * Allows subclasses to specify how to prune input cluster provided to the constructor. + * Allows subclasses to specify how to prune the input cluster provided to the constructor. * @param cluster The input cluster provided to the constructor. * @return The pruned cluster to use in place of the input cluster. */