Add TmfSimpleTimestamp
authorfrancois <fchouinard@gmail.com>
Sat, 11 Feb 2012 21:27:22 +0000 (16:27 -0500)
committerfrancois <fchouinard@gmail.com>
Sat, 11 Feb 2012 21:27:22 +0000 (16:27 -0500)
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfDataEvent.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventContent.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java [new file with mode: 0644]

index 0ea6ff742fc0ca11d73c7934d72071e1c9dc26a4..dd87a401f4ba7a61a144b742db4928a1b023a780 100644 (file)
@@ -29,7 +29,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
  * used as e.g. a location marker (filename:lineno) to indicate where the event
  * was generated.
  */
-public interface ITmfDataEvent {
+public interface ITmfDataEvent extends Cloneable {
 
     /**
      * @return the trace that 'owns' the event
@@ -61,4 +61,9 @@ public interface ITmfDataEvent {
      */
     public String getReference();
 
+    /**
+     * @return a clone of the data event
+     */
+    public ITmfDataEvent clone();
+    
 }
index 2b4240d6fb9d7c870fab2106c9c94a162fe6ae04..f552b07475439fe3d4232fd0c6e71c9b5740dd1d 100644 (file)
@@ -38,6 +38,12 @@ public interface ITmfEventContent extends Cloneable {
      */
     public ITmfEventField[] getFields();
 
+    /**
+     * @param index the field index
+     * @return the corresponding field
+     */
+    public ITmfEventField getField(int index) throws TmfNoSuchFieldException;
+
     /**
      * @param name the field name
      * @return the corresponding field
index edfc307a7bb1657a7df3ae24c373d7ea296ab9d7..8387216a300c3a7d5ec5aa2ace7d36eb8f04fca8 100644 (file)
@@ -16,7 +16,7 @@ package org.eclipse.linuxtools.tmf.core.event;
  * <b><u>ITmfEventField</u></b>
  * <p>
  */
-public interface ITmfEventField {
+public interface ITmfEventField extends Cloneable {
 
     /**
      * @return the field name
@@ -33,4 +33,9 @@ public interface ITmfEventField {
      */
     public ITmfEventField[] getSubFields();
 
+    /**
+     * @return a clone of the event type
+     */
+    public ITmfEventType clone();
+
 }
index 02658822a6fba63c71e071ff3052f0b48a9421ad..089a9b3176b5322d5dd6209af0dbca31098ebd63 100644 (file)
@@ -15,6 +15,20 @@ package org.eclipse.linuxtools.tmf.core.event;
 /**
  * <b><u>ITmfTimestamp</u></b>
  * <p>
+ * The fundamental time reference in the TMF.
+ * <p>
+ * It defines a generic timestamp interface in its most basic form:
+ * <ul>
+ * <li>timestamp = [value] * 10**[scale] +/- [precision]
+ * </ul>
+ * Where:
+ * <ul>
+ * <li>[value] is an unstructured integer value
+ * <li>[scale] is the magnitude of the value wrt some application-specific
+ * base unit (e.g. the second)
+ * <li>[precision] indicates the error on the value (useful for comparing
+ * timestamps in different scales). Default: 0.
+ * </ul>
  */
 public interface ITmfTimestamp extends Cloneable, Comparable<ITmfTimestamp> {
 
@@ -59,10 +73,14 @@ public interface ITmfTimestamp extends Cloneable, Comparable<ITmfTimestamp> {
      */
     public ITmfTimestamp getDelta(ITmfTimestamp ts);
 
-    // Cloneable
+    /**
+     * @return a clone of the timestamp
+     */
     public ITmfTimestamp clone();
     
-    // Comparable
+    /* (non-Javadoc)
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
     public int compareTo(ITmfTimestamp ts);
 
 }
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java
new file mode 100644 (file)
index 0000000..f0a7bcd
--- /dev/null
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.event;
+
+/**
+ * <b><u>TmfSimpleTimestamp</u></b>
+ * <p>
+ * A simplified timestamp where scale and precision are set to 0.
+ */
+public class TmfSimpleTimestamp extends TmfTimestamp {
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Default constructor
+     */
+    public TmfSimpleTimestamp() {
+        this(0);
+    }
+
+    /**
+     * Full constructor
+     *
+     * @param value the timestamp value
+     */
+    public TmfSimpleTimestamp(long value) {
+        super(value, 0, 0);
+    }
+
+    /**
+     * Copy constructor
+     * 
+     * @param timestamp the timestamp to copy
+     */
+    public TmfSimpleTimestamp(TmfSimpleTimestamp timestamp) {
+        if (timestamp == null || timestamp.getScale() != 0 || timestamp.getPrecision() != 0)
+            throw new IllegalArgumentException();
+        fValue = timestamp.getValue();
+        fScale = 0;
+        fPrecision = 0;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTimestamp
+    // ------------------------------------------------------------------------
+
+    @Override
+    public ITmfTimestamp normalize(long offset, int scale) throws ArithmeticException {
+        if (scale == 0) {
+            return new TmfSimpleTimestamp(fValue + offset);
+        }
+        return super.normalize(offset, scale);
+    }
+
+    @Override
+    public int compareTo(ITmfTimestamp ts, boolean withinPrecision) {
+        if (ts instanceof TmfSimpleTimestamp) {
+            long delta = fValue - ts.getValue();
+            return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
+        }
+        return super.compareTo(ts, withinPrecision);
+    }
+
+    @Override
+    public ITmfTimestamp getDelta(ITmfTimestamp ts) {
+        if (ts instanceof TmfSimpleTimestamp) {
+            return new TmfSimpleTimestamp(fValue - ts.getValue());
+        }
+        return super.getDelta(ts);
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public boolean equals(Object other) {
+        if (this == other)
+            return true;
+        if (other == null)
+            return false;
+        if (!(other instanceof TmfSimpleTimestamp))
+            return super.equals(other);
+        TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
+        return compareTo(ts, false) == 0;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfSimpleTimestamp [fValue=" + fValue + ", fScale=" + fScale + ", fPrecision=" + fPrecision + "]";
+    }
+
+}
This page took 0.037073 seconds and 5 git commands to generate.