tmf: Remove the precision concept from ITmfTimestamp
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / timestamp / TmfTimestampDelta.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * @since 2.0
22 */
23 public class TmfTimestampDelta extends TmfTimestamp {
24
25 // ------------------------------------------------------------------------
26 // Members
27 // ------------------------------------------------------------------------
28
29 // ------------------------------------------------------------------------
30 // Constructors
31 // ------------------------------------------------------------------------
32 /**
33 * Default constructor
34 */
35 public TmfTimestampDelta() {
36 super();
37 }
38
39 /**
40 * Simple constructor (scale = precision = 0)
41 *
42 * @param value the timestamp value
43 */
44
45 public TmfTimestampDelta(long value) {
46 super(value);
47 }
48
49 /**
50 * Simple constructor (precision = 0)
51 *
52 * @param value the timestamp value
53 * @param scale the timestamp scale
54 */
55 public TmfTimestampDelta(long value, int scale) {
56 super(value, scale);
57 }
58
59
60 /**
61 * Copy constructor
62 *
63 * @param timestamp the timestamp to copy
64 */
65 public TmfTimestampDelta(ITmfTimestamp timestamp) {
66 super(timestamp);
67 }
68
69 // ------------------------------------------------------------------------
70 // Operations
71 // ------------------------------------------------------------------------
72
73 @Override
74 public ITmfTimestamp normalize(final long offset, final int scale) {
75 ITmfTimestamp nts = super.normalize(offset, scale);
76 return new TmfTimestampDelta(nts.getValue(), nts.getScale());
77 }
78
79 @Override
80 public String toString() {
81 return toString(TmfTimestampFormat.getDefaulIntervalFormat());
82 }
83
84 @Override
85 public String toString(TmfTimestampFormat format) {
86 if (getValue() < 0) {
87 TmfTimestampDelta tmpTs = new TmfTimestampDelta(-getValue(), getScale());
88 return "-" + tmpTs.toString(format); //$NON-NLS-1$
89 }
90 TmfTimestampFormat deltaFormat = new TmfTimestampFormat(format.toPattern());
91 deltaFormat.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
92 return super.toString(deltaFormat);
93 }
94 }
This page took 0.0456 seconds and 6 git commands to generate.