/*******************************************************************************
* 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 {
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
*/
// ------------------------------------------------------------------------
/**
- * The timestamp raw value (mantissa)
+ * The timestamp raw value (mantissa) in nanoseconds
*/
private long fValue;
* Default constructor
*/
public TmfTimestamp() {
- this(0, 0, 0);
+ this(0, ITmfTimestamp.SECOND_SCALE, 0);
}
/**
* @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
*/
/**
* Full constructor
- *
+ *
* @param value the timestamp value
* @param scale the timestamp scale
* @param precision the timestamp precision
/**
* Copy constructor
- *
+ *
* @param timestamp the timestamp to copy
*/
public TmfTimestamp(final ITmfTimestamp timestamp) {
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;
}
* @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);
+ }
}
}