From c655e3414c5c831beea09ce81d1b1eade9a6637f Mon Sep 17 00:00:00 2001 From: Janus Varmarken Date: Thu, 3 May 2018 17:02:11 -0700 Subject: [PATCH] Add getPackets to Conversation's API. --- .../main/java/edu/uci/iotproject/Conversation.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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. -- 2.34.1