tmf: Add generics to ITmfEventAspect
[deliverable/tracecompass.git] / pcap / org.eclipse.tracecompass.tmf.pcap.core / src / org / eclipse / tracecompass / internal / tmf / pcap / core / trace / PcapTrace.java
index bc43a39492dce3598454840fe12b48081d0787f3..277f8b89d4b4a68323a6a1f38913fede5ba71996 100644 (file)
@@ -15,6 +15,7 @@
 package org.eclipse.tracecompass.internal.tmf.pcap.core.trace;
 
 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
 
 import java.io.IOException;
 import java.nio.channels.ClosedChannelException;
@@ -28,7 +29,6 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
 import org.eclipse.tracecompass.internal.pcap.core.protocol.pcap.PcapPacket;
@@ -45,8 +45,8 @@ import org.eclipse.tracecompass.internal.tmf.pcap.core.util.PcapEventFactory;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
@@ -64,22 +64,22 @@ import com.google.common.collect.ImmutableMap;
  *
  * @author Vincent Perot
  */
-public class PcapTrace extends TmfTrace implements ITmfTraceProperties {
+public class PcapTrace extends TmfTrace implements ITmfPropertiesProvider {
 
     /** pcap trace type id as defined in plugin.xml */
     public static final String TRACE_TYPE_ID = "org.eclipse.linuxtools.tmf.pcap.core.pcaptrace"; //$NON-NLS-1$
 
-    private @NonNull static final Collection<ITmfEventAspect> PCAP_ASPECTS =
-            checkNotNull(ImmutableList.of(
+    private static final Collection<ITmfEventAspect<?>> PCAP_ASPECTS =
+            ImmutableList.of(
                     ITmfEventAspect.BaseAspects.TIMESTAMP,
                     PcapSourceAspect.INSTANCE,
                     PcapDestinationAspect.INSTANCE,
                     PcapReferenceAspect.INSTANCE,
                     PcapProtocolAspect.INSTANCE,
                     ITmfEventAspect.BaseAspects.CONTENTS
-                    ));
+                    );
 
-    private @NonNull static final String EMPTY_STRING = ""; //$NON-NLS-1$
+    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
     private static final int CONFIDENCE = 50;
     private @Nullable PcapFile fPcapFile;
     private @Nullable Map<String, String> fTraceProperties = null;
@@ -128,7 +128,7 @@ public class PcapTrace extends TmfTrace implements ITmfTraceProperties {
     }
 
     @Override
-    public Iterable<ITmfEventAspect> getEventAspects() {
+    public Iterable<ITmfEventAspect<?>> getEventAspects() {
         return PCAP_ASPECTS;
     }
 
@@ -244,26 +244,26 @@ public class PcapTrace extends TmfTrace implements ITmfTraceProperties {
     }
 
     @Override
-    public synchronized Map<String, String> getTraceProperties() {
+    public synchronized Map<String, String> getProperties() {
         PcapFile pcap = fPcapFile;
         if (pcap == null) {
-            return checkNotNull(Collections.<String, String> emptyMap());
+            return Collections.emptyMap();
         }
 
-        Map<String, String> properties = fTraceProperties;
-        if (properties == null) {
-            ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder();
-            builder.put(Messages.PcapTrace_Version, String.format("%d%c%d", pcap.getMajorVersion(), '.', pcap.getMinorVersion())); //$NON-NLS-1$
-            builder.put(Messages.PcapTrace_TimeZoneCorrection, pcap.getTimeZoneCorrection() + " s"); //$NON-NLS-1$
-            builder.put(Messages.PcapTrace_TimestampAccuracy, String.valueOf(pcap.getTimeAccuracy()));
-            builder.put(Messages.PcapTrace_MaxSnapLength, pcap.getSnapLength() + " bytes"); //$NON-NLS-1$
-            builder.put(Messages.PcapTrace_LinkLayerHeaderType, LinkTypeHelper.toString((int) pcap.getDataLinkType()) + " (" + pcap.getDataLinkType() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
-            builder.put(Messages.PcapTrace_FileEndianness, pcap.getByteOrder().toString());
+        if (fTraceProperties != null) {
+            return fTraceProperties;
+        }
 
-            return checkNotNull(builder.build());
+        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+        builder.put(nullToEmptyString(Messages.PcapTrace_Version), String.format("%d%c%d", pcap.getMajorVersion(), '.', pcap.getMinorVersion())); //$NON-NLS-1$
+        builder.put(nullToEmptyString(Messages.PcapTrace_TimeZoneCorrection), pcap.getTimeZoneCorrection() + " s"); //$NON-NLS-1$
+        builder.put(nullToEmptyString(Messages.PcapTrace_TimestampAccuracy), String.valueOf(pcap.getTimeAccuracy()));
+        builder.put(nullToEmptyString(Messages.PcapTrace_MaxSnapLength), pcap.getSnapLength() + " bytes"); //$NON-NLS-1$
+        builder.put(nullToEmptyString(Messages.PcapTrace_LinkLayerHeaderType), LinkTypeHelper.toString((int) pcap.getDataLinkType()) + " (" + pcap.getDataLinkType() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+        builder.put(nullToEmptyString(Messages.PcapTrace_FileEndianness), nullToEmptyString(pcap.getByteOrder().toString()));
 
-        }
+        fTraceProperties = builder.build();
 
-        return properties;
+        return fTraceProperties;
     }
 }
This page took 0.038063 seconds and 5 git commands to generate.