tmf: Move timestamps to their own package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / parsers / custom / CustomEvent.java
index 01bd80d0dd592d4ccb95efb002e638560b4ee6de..8d4cd2c894d2ad158bc65c93ee72c258ddb0ec29 100644 (file)
@@ -20,48 +20,171 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
+/**
+ * Base event for custom text parsers.
+ *
+ * @author Patrick Tassé
+ */
 public class CustomEvent extends TmfEvent {
 
+    /** Default timestamp scale for text-parser events */
+    public static final byte TIMESTAMP_SCALE = -3;
+
+    /** Input format key */
     protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$
+
+    /** Empty message */
     protected static final String NO_MESSAGE = ""; //$NON-NLS-1$
-    public static final byte TIMESTAMP_SCALE = -3;
 
+    /** Replacement for the super-class' timestamp field */
+    private ITmfTimestamp customEventTimestamp;
+
+    /** Replacement for the super-class' content field */
+    private ITmfEventField customEventContent;
+
+    /** Replacement for the super-class' type field */
+    private ITmfEventType customEventType;
+
+    /** The trace to which this event belongs */
     protected CustomTraceDefinition fDefinition;
+
+    /** The payload data of this event, <field name, value> */
     protected Map<String, String> fData;
+
     private TmfEventField[] fColumnData;
 
+    /**
+     * Basic constructor.
+     *
+     * @param definition
+     *            The trace definition to which this event belongs
+     */
     public CustomEvent(CustomTraceDefinition definition) {
         fDefinition = definition;
         fData = new HashMap<String, String>();
     }
 
+    /**
+     * Build a new CustomEvent from an existing TmfEvent.
+     *
+     * @param definition
+     *            The trace definition to which this event belongs
+     * @param other
+     *            The TmfEvent to copy
+     */
     public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {
         super(other);
         fDefinition = definition;
         fData = new HashMap<String, String>();
+
+        /* Set our overridden fields */
+        customEventTimestamp = other.getTimestamp();
+        customEventContent = other.getContent();
+        customEventType = other.getType();
     }
 
-    public CustomEvent(CustomTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {
-        super(parentTrace, timestamp, source, type, null, reference);
+    /**
+     * Full constructor
+     *
+     * @param definition
+     *            Trace definition of this event
+     * @param parentTrace
+     *            Parent trace object
+     * @param timestamp
+     *            Timestamp of this event
+     * @param source
+     *            Source of the event
+     * @param type
+     *            Event type
+     * @param reference
+     *            Event reference
+     */
+    public CustomEvent(CustomTraceDefinition definition, ITmfTrace parentTrace,
+            ITmfTimestamp timestamp, String source, TmfEventType type,
+            String reference) {
+        /* Do not use upstream's fields for stuff we override */
+        super(parentTrace, null, source, null, null, reference);
         fDefinition = definition;
         fData = new HashMap<String, String>();
+
+        /* Set our overridden fields */
+        customEventTimestamp = timestamp;
+        customEventContent = null;
+        customEventType = type;
     }
 
+    // ------------------------------------------------------------------------
+    // Overridden getters
+    // ------------------------------------------------------------------------
+
     @Override
     public ITmfTimestamp getTimestamp() {
         if (fData != null) {
             processData();
         }
-        return super.getTimestamp();
+        return customEventTimestamp;
+    }
+
+    @Override
+    public ITmfEventField getContent() {
+        return customEventContent;
+    }
+
+    @Override
+    public ITmfEventType getType() {
+        return customEventType;
+    }
+
+    // ------------------------------------------------------------------------
+    // Setters
+    // ------------------------------------------------------------------------
+
+    /**
+     * Set this event's timestamp
+     *
+     * @param timestamp
+     *            The new timestamp
+     */
+    protected void setTimestamp(ITmfTimestamp timestamp) {
+        customEventTimestamp = timestamp;
     }
 
+    /**
+     * Set this event's content
+     *
+     * @param content
+     *            The new content
+     */
+    protected void setContent(ITmfEventField content) {
+        customEventContent = content;
+    }
+
+    /**
+     * Set this event's type
+     *
+     * @param type
+     *            The new type
+     */
+    protected void setType(ITmfEventType type) {
+        customEventType = type;
+    }
+
+    // ------------------------------------------------------------------------
+    // Other operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return The event fields
+     */
     public TmfEventField[] extractItemFields() {
         if (fData != null) {
             processData();
@@ -96,25 +219,22 @@ public class CustomEvent extends TmfEvent {
                 fColumnData[i++] = new TmfEventField(outputColumn.name, (value != null ? value : "")); //$NON-NLS-1$
             }
         }
-        CustomEventContent content = (CustomEventContent) getContent();
-        content.setFields(fColumnData);
+        CustomEventContent curContent = (CustomEventContent) getContent();
+        setContent(new CustomEventContent(curContent.getName(), curContent.getValue(), fColumnData));
         fData = null;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
         result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode());
+        result = prime * result + ((customEventTimestamp == null) ? 0 : customEventTimestamp.hashCode());
+        result = prime * result + ((customEventContent == null) ? 0 : customEventContent.hashCode());
+        result = prime * result + ((customEventType == null) ? 0 : customEventType.hashCode());
         return result;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
     public boolean equals(Object obj) {
         if (this == obj) {
@@ -134,6 +254,31 @@ public class CustomEvent extends TmfEvent {
         } else if (!fDefinition.equals(other.fDefinition)) {
             return false;
         }
+
+        if (customEventTimestamp == null) {
+            if (other.customEventTimestamp != null) {
+                return false;
+            }
+        } else if (!customEventTimestamp.equals(other.customEventTimestamp)) {
+            return false;
+        }
+
+        if (customEventContent == null) {
+            if (other.customEventContent != null) {
+                return false;
+            }
+        } else if (!customEventContent.equals(other.customEventContent)) {
+            return false;
+        }
+
+        if (customEventType == null) {
+            if (other.customEventType != null) {
+                return false;
+            }
+        } else if (!customEventType.equals(other.customEventType)) {
+            return false;
+        }
+
         return true;
     }
 
This page took 0.044429 seconds and 5 git commands to generate.