1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.core
.synchronization
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.TimestampTransformFactory
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
21 * Constant transform, just offset your timestamp with another.
23 * @author Matthew Khouzam
25 public class TmfConstantTransform
implements ITmfTimestampTransformInvertible
{
30 private static final long serialVersionUID
= 417299521984404532L;
31 private final long fOffset
;
36 public TmfConstantTransform() {
37 // we really should be using an identity transform here.
42 * Constructor with offset
45 * The offset of the linear transform in nanoseconds
47 public TmfConstantTransform(long offset
) {
52 * Constructor with offset timestamp
55 * The offset of the linear transform
57 public TmfConstantTransform(@NonNull ITmfTimestamp offset
) {
58 this(offset
.toNanos());
62 public ITmfTimestamp
transform(ITmfTimestamp timestamp
) {
63 return timestamp
.normalize(fOffset
, ITmfTimestamp
.NANOSECOND_SCALE
);
70 * the timestamp in nanoseconds
71 * @return the timestamp in nanoseconds
74 public long transform(long timestamp
) {
75 return fOffset
+ timestamp
;
79 public ITmfTimestampTransform
composeWith(ITmfTimestampTransform composeWith
) {
80 if (composeWith
.equals(TmfTimestampTransform
.IDENTITY
)) {
81 /* If composing with identity, just return this */
83 } else if (composeWith
instanceof TmfConstantTransform
) {
84 TmfConstantTransform tct
= (TmfConstantTransform
) composeWith
;
85 final long offset
= fOffset
+ tct
.fOffset
;
87 return TmfTimestampTransform
.IDENTITY
;
89 return new TmfConstantTransform(offset
);
90 } else if (composeWith
instanceof TmfTimestampTransformLinear
) {
91 throw new UnsupportedOperationException("Cannot compose a constant and linear transform yet"); //$NON-NLS-1$
94 * We do not know what to do with this kind of transform, just
102 public String
toString() {
103 StringBuilder builder
= new StringBuilder();
104 builder
.append("TmfConstantTransform [ offset = "); //$NON-NLS-1$
105 builder
.append(fOffset
);
106 builder
.append(" ]"); //$NON-NLS-1$
107 return builder
.toString();
111 public ITmfTimestampTransform
inverse() {
112 return TimestampTransformFactory
.createWithOffset(-1 * fOffset
);