org.eclipse.linuxtools.internal.tmf.core.request;x-friends:="org.eclipse.linuxtools.tmf.core.tests",
org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.partial;x-friends:="org.eclipse.linuxtools.statesystem.core.tests",
org.eclipse.linuxtools.internal.tmf.core.statesystem.mipmap;x-friends:="org.eclipse.linuxtools.tmf.core.tests",
+ org.eclipse.linuxtools.internal.tmf.core.synchronization;x-friends:="org.eclipse.linuxtools.tmf.core.tests",
org.eclipse.linuxtools.internal.tmf.core.trace;x-friends:="org.eclipse.linuxtools.tmf.core.tests",
org.eclipse.linuxtools.internal.tmf.core.trace.indexer;x-friends:="org.eclipse.linuxtools.tmf.core.tests",
org.eclipse.linuxtools.tmf.core,
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 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:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.core.synchronization;
+
+import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
+import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform;
+import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransformLinear;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
+
+/**
+ * Constant transform, just offset your timestamp with another.
+ *
+ * @author Matthew Khouzam
+ */
+public class TmfConstantTransform implements ITmfTimestampTransform {
+
+ /**
+ * Serial ID
+ */
+ private static final long serialVersionUID = 417299521984404532L;
+ private ITmfTimestamp fOffset;
+
+ /**
+ * Default constructor
+ */
+ public TmfConstantTransform() {
+ fOffset = new TmfNanoTimestamp(0);
+ }
+
+ /**
+ * Constructor with offset
+ *
+ * @param offset
+ * The offset of the linear transform in nanoseconds
+ */
+ public TmfConstantTransform(long offset) {
+ fOffset = new TmfNanoTimestamp(offset);
+ }
+
+ /**
+ * Constructor with offset timestamp
+ *
+ * @param offset
+ * The offset of the linear transform
+ */
+ public TmfConstantTransform(ITmfTimestamp offset) {
+ fOffset = offset;
+ }
+
+ @Override
+ public ITmfTimestamp transform(ITmfTimestamp timestamp) {
+ return fOffset.normalize(timestamp.getValue(), timestamp.getScale());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param timestamp
+ * the timestamp in nanoseconds
+ * @return the timestamp in nanoseconds
+ */
+ @Override
+ public long transform(long timestamp) {
+ return fOffset.normalize(timestamp, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ }
+
+ @Override
+ public ITmfTimestampTransform composeWith(ITmfTimestampTransform composeWith) {
+ if (composeWith.equals(TmfTimestampTransform.IDENTITY)) {
+ /* If composing with identity, just return this */
+ return this;
+ } else if (composeWith instanceof TmfConstantTransform) {
+ TmfConstantTransform tct = (TmfConstantTransform) composeWith;
+ return new TmfConstantTransform(fOffset.getValue() + tct.fOffset.getValue());
+ } else if (composeWith instanceof TmfTimestampTransformLinear) {
+ throw new UnsupportedOperationException("Cannot compose a constant and linear transform yet"); //$NON-NLS-1$
+ } else {
+ /*
+ * We do not know what to do with this kind of transform, just
+ * return this
+ */
+ return this;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("TmfConstantTransform [fOffset="); //$NON-NLS-1$
+ builder.append(fOffset);
+ builder.append("]"); //$NON-NLS-1$
+ return builder.toString();
+ }
+
+}
* Transforms a timestamp value
*
* @param timestamp
- * The timestamp to transform
+ * The timestamp to transform in nanoseconds
* @return the transformed value
*/
long transform(long timestamp);
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 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:
+ * Matthew Khouzam - Initial implementation and API
+ *******************************************************************************/
+package org.eclipse.linuxtools.tmf.core.synchronization;
+
+import java.math.BigDecimal;
+
+import org.eclipse.linuxtools.internal.tmf.core.synchronization.TmfConstantTransform;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+
+/**
+ * A factory to generate timestamp tranforms
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public final class TimestampTransformFactory {
+
+ private TimestampTransformFactory() {
+ }
+
+ /**
+ * Create an offsetted transform
+ *
+ * @param offset
+ * the offset in long format, nanosecond scale
+ * @return the offsetted transform
+ */
+ public static ITmfTimestampTransform create(long offset) {
+ if (offset == 0) {
+ return TmfTimestampTransform.IDENTITY;
+ }
+ return new TmfConstantTransform(offset);
+ }
+
+ /**
+ * Create an offsetted transform
+ *
+ * @param offset
+ * the offset in a timestamp with scale
+ * @return the offsetted transform
+ */
+ public static ITmfTimestampTransform create(ITmfTimestamp offset) {
+ if (offset.getValue() == 0) {
+ return TmfTimestampTransform.IDENTITY;
+ }
+ return new TmfConstantTransform(offset);
+ }
+
+ /**
+ * Create an offsetted and sloped transform
+ *
+ * @param factor
+ * the slope
+ * @param offset
+ * the offset
+ * @return the transform
+ */
+ public static ITmfTimestampTransform create(double factor, ITmfTimestamp offset) {
+ if (factor == 1.0) {
+ return create(offset);
+ }
+ return new TmfTimestampTransformLinear(factor, offset.normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
+ }
+
+ /**
+ * Create an offsetted and sloped transform
+ *
+ * @param factor
+ * the slope
+ * @param offset
+ * the offset in nanoseconds
+ * @return the transform
+ */
+ public static ITmfTimestampTransform create(double factor, long offset) {
+ if (factor == 1.0) {
+ return create(offset);
+ }
+ return new TmfTimestampTransformLinear(factor, offset);
+ }
+
+ /**
+ * Create an offsetted and sloped transform using bigDecimals
+ *
+ * @param factor
+ * the slope
+ * @param offset
+ * the offset in nanoseconds
+ * @return the transform
+ */
+ public static ITmfTimestampTransform create(BigDecimal factor, BigDecimal offset) {
+ if (factor.equals(BigDecimal.ONE)) {
+ return create(offset.longValueExact());
+ }
+ return new TmfTimestampTransformLinear(factor, offset);
+ }
+
+}