tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / timestamp / TmfTimestampDelta.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.tracecompass.tmf.core.timestamp;
13
14 import java.util.TimeZone;
15
16 /**
17 * A generic timestamp implementation for delta between timestamps.
18 * The toString() method takes negative values into consideration.
19 *
20 * @author Bernd Hufmann
21 */
22 public class TmfTimestampDelta extends TmfTimestamp {
23
24 // ------------------------------------------------------------------------
25 // Members
26 // ------------------------------------------------------------------------
27
28 // ------------------------------------------------------------------------
29 // Constructors
30 // ------------------------------------------------------------------------
31 /**
32 * Default constructor
33 */
34 public TmfTimestampDelta() {
35 super();
36 }
37
38 /**
39 * Simple constructor (scale = precision = 0)
40 *
41 * @param value the timestamp value
42 */
43
44 public TmfTimestampDelta(long value) {
45 super(value);
46 }
47
48 /**
49 * Simple constructor (precision = 0)
50 *
51 * @param value the timestamp value
52 * @param scale the timestamp scale
53 */
54 public TmfTimestampDelta(long value, int scale) {
55 super(value, scale);
56 }
57
58
59 /**
60 * Copy constructor
61 *
62 * @param timestamp the timestamp to copy
63 */
64 public TmfTimestampDelta(ITmfTimestamp timestamp) {
65 super(timestamp);
66 }
67
68 // ------------------------------------------------------------------------
69 // Operations
70 // ------------------------------------------------------------------------
71
72 @Override
73 public ITmfTimestamp normalize(final long offset, final int scale) {
74 ITmfTimestamp nts = super.normalize(offset, scale);
75 return new TmfTimestampDelta(nts.getValue(), nts.getScale());
76 }
77
78 @Override
79 public String toString() {
80 return toString(TmfTimestampFormat.getDefaulIntervalFormat());
81 }
82
83 @Override
84 public String toString(TmfTimestampFormat format) {
85 if (getValue() < 0) {
86 TmfTimestampDelta tmpTs = new TmfTimestampDelta(-getValue(), getScale());
87 return "-" + tmpTs.toString(format); //$NON-NLS-1$
88 }
89 TmfTimestampFormat deltaFormat = new TmfTimestampFormat(format.toPattern());
90 deltaFormat.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
91 return super.toString(deltaFormat);
92 }
93 }
This page took 0.032957 seconds and 5 git commands to generate.