tmf: Do not define base aspects in the interface
[deliverable/tracecompass.git] / pcap / org.eclipse.tracecompass.tmf.pcap.core / src / org / eclipse / tracecompass / internal / tmf / pcap / core / trace / PcapTrace.java
index 42e30d995596ed1f73d6c2fa114f480f2ff884d3..404b98105f649e278a19100e626a610b026c2253 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,6 +29,8 @@ 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.DefaultLocation;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 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;
@@ -42,10 +45,11 @@ import org.eclipse.tracecompass.internal.tmf.pcap.core.event.aspect.PcapReferenc
 import org.eclipse.tracecompass.internal.tmf.pcap.core.event.aspect.PcapSourceAspect;
 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.TmfBaseAspects;
 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;
@@ -63,20 +67,20 @@ import com.google.common.collect.ImmutableMap;
  *
  * @author Vincent Perot
  */
-public class PcapTrace extends TmfTrace implements ITmfTraceProperties, AutoCloseable {
+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 static final Collection<ITmfEventAspect> PCAP_ASPECTS =
-            checkNotNull(ImmutableList.of(
-                    ITmfEventAspect.BaseAspects.TIMESTAMP,
+    private static final Collection<ITmfEventAspect<?>> PCAP_ASPECTS =
+            ImmutableList.of(
+                    TmfBaseAspects.getTimestampAspect(),
                     PcapSourceAspect.INSTANCE,
                     PcapDestinationAspect.INSTANCE,
                     PcapReferenceAspect.INSTANCE,
                     PcapProtocolAspect.INSTANCE,
-                    ITmfEventAspect.BaseAspects.CONTENTS
-                    ));
+                    TmfBaseAspects.getContentsAspect()
+                    );
 
     private static final String EMPTY_STRING = ""; //$NON-NLS-1$
     private static final int CONFIDENCE = 50;
@@ -113,6 +117,7 @@ public class PcapTrace extends TmfTrace implements ITmfTraceProperties, AutoClos
     }
 
     @Override
+    @NonNullByDefault({DefaultLocation.TYPE_ARGUMENT})
     public synchronized void initTrace(@Nullable IResource resource, @Nullable String path, @Nullable Class<? extends ITmfEvent> type) throws TmfTraceException {
         super.initTrace(resource, path, type);
         if (path == null) {
@@ -127,7 +132,7 @@ public class PcapTrace extends TmfTrace implements ITmfTraceProperties, AutoClos
     }
 
     @Override
-    public Iterable<ITmfEventAspect> getEventAspects() {
+    public Iterable<ITmfEventAspect<?>> getEventAspects() {
         return PCAP_ASPECTS;
     }
 
@@ -243,31 +248,26 @@ public class PcapTrace extends TmfTrace implements ITmfTraceProperties, AutoClos
     }
 
     @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());
-
-            return checkNotNull(builder.build());
-
+        if (fTraceProperties != null) {
+            return fTraceProperties;
         }
 
-        return properties;
-    }
+        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()));
 
-    @Override
-    public void close() {
-        dispose();
+        fTraceProperties = builder.build();
+
+        return fTraceProperties;
     }
 }
This page took 0.053385 seconds and 5 git commands to generate.