From: Janus Varmarken Date: Fri, 4 May 2018 00:02:11 +0000 (-0700) Subject: Add getPackets to Conversation's API. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c655e3414c5c831beea09ce81d1b1eade9a6637f;p=pingpong.git Add getPackets to Conversation's API. --- diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java index f8ee398..6a24195 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java @@ -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 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.