From: francois Date: Sat, 11 Feb 2012 21:27:22 +0000 (-0500) Subject: Add TmfSimpleTimestamp X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=7636a88e531235081631f57945dc61603f4abafa;p=deliverable%2Ftracecompass.git Add TmfSimpleTimestamp --- diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfDataEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfDataEvent.java index 0ea6ff742f..dd87a401f4 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfDataEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfDataEvent.java @@ -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(); + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventContent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventContent.java index 2b4240d6fb..f552b07475 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventContent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventContent.java @@ -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 diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java index edfc307a7b..8387216a30 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java @@ -16,7 +16,7 @@ package org.eclipse.linuxtools.tmf.core.event; * ITmfEventField *

*/ -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(); + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java index 02658822a6..089a9b3176 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java @@ -15,6 +15,20 @@ package org.eclipse.linuxtools.tmf.core.event; /** * ITmfTimestamp *

+ * The fundamental time reference in the TMF. + *

+ * It defines a generic timestamp interface in its most basic form: + *

+ * Where: + * */ public interface ITmfTimestamp extends Cloneable, Comparable { @@ -59,10 +73,14 @@ public interface ITmfTimestamp extends Cloneable, Comparable { */ 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 index 0000000000..f0a7bcd37e --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java @@ -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; + +/** + * TmfSimpleTimestamp + *

+ * 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 + "]"; + } + +}