Add getPackets to Conversation's API.
authorJanus Varmarken <varmarken@gmail.com>
Fri, 4 May 2018 00:02:11 +0000 (17:02 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Fri, 4 May 2018 00:02:11 +0000 (17:02 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java

index f8ee398f588f5c8f482250cc9dad74aad35452c9..6a241953e89fb8bf3828c62f2b043f850fdf2311 100644 (file)
@@ -5,6 +5,7 @@ import org.pcap4j.packet.IpV4Packet;
 import org.pcap4j.packet.TcpPacket;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
@@ -78,6 +79,16 @@ public class Conversation {
         mPackets.add(packet);
     }
 
+    /**
+     * Get a list of packets pertaining to this {@code Conversation}.
+     * The returned list is a read-only list.
+     * @return the list of packets pertaining to this {@code Conversation}.
+     */
+    public List<PcapPacket> getPackets() {
+        // Return read-only view to prevent external code from manipulating internal state (preserve invariant).
+        return Collections.unmodifiableList(mPackets);
+    }
+
     // =========================================================================================================
     // We simply reuse equals and hashCode methods of String.class to be able to use this class as a key
     // in a Map.