~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/synchronization/TmfConstantTransform.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2014 Ericsson
 
3
 *
 
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
 
8
 *
 
9
 * Contributors:
 
10
 *   Matthew Khouzam - Initial API and implementation
 
11
 *******************************************************************************/
 
12
 
 
13
package org.eclipse.linuxtools.internal.tmf.core.synchronization;
 
14
 
 
15
import org.eclipse.jdt.annotation.NonNull;
 
16
import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
 
17
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 
18
import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
 
19
 
 
20
/**
 
21
 * Constant transform, just offset your timestamp with another.
 
22
 *
 
23
 * @author Matthew Khouzam
 
24
 */
 
25
public class TmfConstantTransform implements ITmfTimestampTransform {
 
26
 
 
27
    /**
 
28
     * Serial ID
 
29
     */
 
30
    private static final long serialVersionUID = 417299521984404532L;
 
31
    private final long fOffset;
 
32
 
 
33
    /**
 
34
     * Default constructor
 
35
     */
 
36
    public TmfConstantTransform() {
 
37
        // we really should be using an identity transform here.
 
38
        fOffset = 0;
 
39
    }
 
40
 
 
41
    /**
 
42
     * Constructor with offset
 
43
     *
 
44
     * @param offset
 
45
     *            The offset of the linear transform in nanoseconds
 
46
     */
 
47
    public TmfConstantTransform(long offset) {
 
48
        fOffset = offset;
 
49
    }
 
50
 
 
51
    /**
 
52
     * Constructor with offset timestamp
 
53
     *
 
54
     * @param offset
 
55
     *            The offset of the linear transform
 
56
     */
 
57
    public TmfConstantTransform(@NonNull ITmfTimestamp offset) {
 
58
        this(new TmfNanoTimestamp(offset).getValue());
 
59
    }
 
60
 
 
61
    @Override
 
62
    public ITmfTimestamp transform(ITmfTimestamp timestamp) {
 
63
        return timestamp.normalize(fOffset, ITmfTimestamp.NANOSECOND_SCALE);
 
64
    }
 
65
 
 
66
    /**
 
67
     * {@inheritDoc}
 
68
     *
 
69
     * @param timestamp
 
70
     *            the timestamp in nanoseconds
 
71
     * @return the timestamp in nanoseconds
 
72
     */
 
73
    @Override
 
74
    public long transform(long timestamp) {
 
75
        return fOffset + timestamp;
 
76
    }
 
77
 
 
78
    @Override
 
79
    public ITmfTimestampTransform composeWith(ITmfTimestampTransform composeWith) {
 
80
        if (composeWith.equals(TmfTimestampTransform.IDENTITY)) {
 
81
            /* If composing with identity, just return this */
 
82
            return this;
 
83
        } else if (composeWith instanceof TmfConstantTransform) {
 
84
            TmfConstantTransform tct = (TmfConstantTransform) composeWith;
 
85
            final long offset = fOffset + tct.fOffset;
 
86
            if (offset == 0) {
 
87
                return TmfTimestampTransform.IDENTITY;
 
88
            }
 
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$
 
92
        } else {
 
93
            /*
 
94
             * We do not know what to do with this kind of transform, just
 
95
             * return this
 
96
             */
 
97
            return this;
 
98
        }
 
99
    }
 
100
 
 
101
    @Override
 
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();
 
108
    }
 
109
 
 
110
}