ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.pcap.core / src / org / eclipse / linuxtools / internal / tmf / pcap / core / event / PcapEvent.java
index 77a3bf41b71145e30fc3d65c3cff93cfeb48de16..705c52198499b76df33ef0f49ea02237b77078e2 100644 (file)
@@ -13,7 +13,7 @@
 package org.eclipse.linuxtools.internal.tmf.pcap.core.event;
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -50,7 +50,11 @@ public class PcapEvent extends TmfEvent {
     private static final String EMPTY_STRING = ""; //$NON-NLS-1$
 
     private final Packet fPacket;
-    private @Nullable List<TmfPcapProtocol> fList;
+
+    /**
+     * Lazy-loaded field representing all the protocols in this event
+     */
+    private transient @Nullable Collection<TmfPcapProtocol> fProtocols;
 
     /**
      * Full constructor.
@@ -167,15 +171,15 @@ public class PcapEvent extends TmfEvent {
     }
 
     /**
-     * Method that returns a list of all the protocols in this PcapEvent.
+     * Method that returns all the protocols in this PcapEvent.
      *
      * @return A list containing all the TmfProtocol.
      */
-    public List<TmfPcapProtocol> getProtocols() {
-        if (fList != null) {
-            return fList;
+    public Collection<TmfPcapProtocol> getProtocols() {
+        if (fProtocols != null) {
+            return fProtocols;
         }
-        List<TmfPcapProtocol> list = new ArrayList<>();
+        ImmutableList.Builder<TmfPcapProtocol> builder = new ImmutableList.Builder<>();
         Packet packet = fPacket;
 
         // Go to start.
@@ -186,21 +190,21 @@ public class PcapEvent extends TmfEvent {
         if (packet == null) {
             @SuppressWarnings("null")
             @NonNull List<TmfPcapProtocol> emptyList = Collections.EMPTY_LIST;
-            fList = emptyList;
-            return fList;
+            fProtocols = emptyList;
+            return fProtocols;
         }
         // Go through all the packets and add them to list.
-        list.add(ProtocolConversion.wrap(packet.getProtocol()));
+        builder.add(ProtocolConversion.wrap(packet.getProtocol()));
         while (packet != null && packet.getChildPacket() != null) {
             packet = packet.getChildPacket();
             if (packet != null) {
-                list.add(ProtocolConversion.wrap(packet.getProtocol()));
+                builder.add(ProtocolConversion.wrap(packet.getProtocol()));
             }
         }
 
         @SuppressWarnings("null")
-        @NonNull ImmutableList<TmfPcapProtocol> immutableList = ImmutableList.copyOf(list);
-        fList = immutableList;
+        @NonNull ImmutableList<TmfPcapProtocol> immutableList = builder.build();
+        fProtocols = immutableList;
         return immutableList;
     }
 
This page took 0.027546 seconds and 5 git commands to generate.