1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.core
.timestamp
;
14 import java
.util
.TimeZone
;
17 * A generic timestamp implementation for delta between timestamps.
18 * The toString() method takes negative values into consideration.
20 * @author Bernd Hufmann
23 public class TmfTimestampDelta
extends TmfTimestamp
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
35 public TmfTimestampDelta() {
40 * Simple constructor (scale = precision = 0)
42 * @param value the timestamp value
45 public TmfTimestampDelta(long value
) {
50 * Simple constructor (precision = 0)
52 * @param value the timestamp value
53 * @param scale the timestamp scale
55 public TmfTimestampDelta(long value
, int scale
) {
63 * @param timestamp the timestamp to copy
65 public TmfTimestampDelta(ITmfTimestamp timestamp
) {
72 * @param value the timestamp value
73 * @param scale the timestamp scale
74 * @param precision the timestamp precision
76 public TmfTimestampDelta(long value
, int scale
, int precision
) {
77 super(value
, scale
, precision
);
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#normalize(long, int)
88 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
89 ITmfTimestamp nts
= super.normalize(offset
, scale
);
90 return new TmfTimestampDelta(nts
.getValue(), nts
.getScale(), nts
.getPrecision());
94 * @see java.lang.Object#toString()
97 public String
toString() {
98 return toString(TmfTimestampFormat
.getDefaulIntervalFormat());
103 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString(org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat)
106 public String
toString(TmfTimestampFormat format
) {
107 if (getValue() < 0) {
108 TmfTimestampDelta tmpTs
= new TmfTimestampDelta(-getValue(), getScale(), getPrecision());
109 return "-" + tmpTs
.toString(format
); //$NON-NLS-1$
111 TmfTimestampFormat deltaFormat
= new TmfTimestampFormat(format
.toPattern());
112 deltaFormat
.setTimeZone(TimeZone
.getTimeZone("UTC")); //$NON-NLS-1$
113 return super.toString(deltaFormat
);