Implement TmfTimestampFormat
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfTimestamp.java
index 118f8bbc2544665dfd132935420feb50c88debcb..f23b91879048cb748ed2e01f72f74f703d414df4 100644 (file)
@@ -1,25 +1,26 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 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
  *   Thomas Gatterweh  - Updated scaling / synchronization
  *   Francois Chouinard - Refactoring to align with TMF Event Model 1.0
+ *   Francois Chouinard - Implement augmented interface
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.event;
 
-
 /**
  * A generic timestamp implementation. The timestamp is represented by the
- * tuple { value, scale, precision }.
- * 
- * @version 1.0
+ * tuple { value, scale, precision }. By default, timestamps are in the
+ * nanosecond scale.
+ *
+ * @version 1.1
  * @author Francois Chouinard
  */
 public class TmfTimestamp implements ITmfTimestamp, Cloneable {
@@ -40,6 +41,18 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
     public static final ITmfTimestamp BIG_CRUNCH =
             new TmfTimestamp(Long.MAX_VALUE, Integer.MAX_VALUE, 0);
 
+    /**
+     * A more practical definition of "beginning of time"
+     * @since 2.0
+     */
+    public static final ITmfTimestamp PROJECT_IS_FUNDED = BIG_BANG;
+
+    /**
+     * A more practical definition of "end of time"
+     * @since 2.0
+     */
+    public static final ITmfTimestamp PROJECT_IS_CANCELLED = BIG_CRUNCH;
+
     /**
      * Zero
      */
@@ -51,7 +64,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
     // ------------------------------------------------------------------------
 
     /**
-     * The timestamp raw value (mantissa)
+     * The timestamp raw value (mantissa) in nanoseconds
      */
     private long fValue;
 
@@ -73,7 +86,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
      * Default constructor
      */
     public TmfTimestamp() {
-        this(0, 0, 0);
+        this(0, ITmfTimestamp.SECOND_SCALE, 0);
     }
 
     /**
@@ -82,12 +95,12 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
      * @param value the timestamp value
      */
     public TmfTimestamp(final long value) {
-        this(value, 0, 0);
+        this(value, ITmfTimestamp.SECOND_SCALE, 0);
     }
 
     /**
      * Simple constructor (precision = 0)
-     * 
+     *
      * @param value the timestamp value
      * @param scale the timestamp scale
      */
@@ -97,7 +110,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
 
     /**
      * Full constructor
-     * 
+     *
      * @param value the timestamp value
      * @param scale the timestamp scale
      * @param precision the timestamp precision
@@ -110,7 +123,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
 
     /**
      * Copy constructor
-     * 
+     *
      * @param timestamp the timestamp to copy
      */
     public TmfTimestamp(final ITmfTimestamp timestamp) {
@@ -195,8 +208,8 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
         if (fScale == scale && offset == 0) {
             return new TmfTimestamp(this);
         }
-        
-        // In case of big bang and big crunch just return this (no need to normalize) 
+
+        // In case of big bang and big crunch just return this (no need to normalize)
         if (this.equals(BIG_BANG) || this.equals(BIG_CRUNCH)) {
             return this;
         }
@@ -358,9 +371,25 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable {
      * @see java.lang.Object#toString()
      */
     @Override
-    @SuppressWarnings("nls")
     public String toString() {
-        return "TmfTimestamp [fValue=" + fValue + ", fScale=" + fScale + ", fPrecision=" + fPrecision + "]";
+        return toString(TmfTimestampFormat.getDefaulTimeFormat());
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#toString(org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat)
+     */
+    /**
+     * @since 2.0
+     */
+    @Override
+    public String toString(final TmfTimestampFormat format) {
+        try {
+            ITmfTimestamp ts = normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
+            return format.format(ts.getValue());
+        }
+        catch (ArithmeticException e) {
+            return format.format(0);
+        }
     }
 
 }
This page took 0.028495 seconds and 5 git commands to generate.