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;
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.common.core.NonNullUtils;
import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
import org.eclipse.tracecompass.internal.pcap.core.protocol.pcap.PcapPacket;
import org.eclipse.tracecompass.internal.pcap.core.trace.BadPcapFileException;
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;
*
* @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;
}
@Override
- public Iterable<ITmfEventAspect> getEventAspects() {
+ public Iterable<ITmfEventAspect<?>> getEventAspects() {
return PCAP_ASPECTS;
}
}
@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.builder();
- builder.put(NonNullUtils.nullToEmptyString(Messages.PcapTrace_Version), String.format("%d%c%d", pcap.getMajorVersion(), '.', pcap.getMinorVersion())); //$NON-NLS-1$
- builder.put(NonNullUtils.nullToEmptyString(Messages.PcapTrace_TimeZoneCorrection), pcap.getTimeZoneCorrection() + " s"); //$NON-NLS-1$
- builder.put(NonNullUtils.nullToEmptyString(Messages.PcapTrace_TimestampAccuracy), String.valueOf(pcap.getTimeAccuracy()));
- builder.put(NonNullUtils.nullToEmptyString(Messages.PcapTrace_MaxSnapLength), pcap.getSnapLength() + " bytes"); //$NON-NLS-1$
- builder.put(NonNullUtils.nullToEmptyString(Messages.PcapTrace_LinkLayerHeaderType), LinkTypeHelper.toString((int) pcap.getDataLinkType()) + " (" + pcap.getDataLinkType() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- builder.put(NonNullUtils.nullToEmptyString(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;
}
}