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;
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.
}
/**
- * 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.
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;
}