1 /*******************************************************************************
2 * Copyright (c) 2012 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 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Standardize on the default toString()
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.timestamp
;
17 * A simplified timestamp where scale and precision are set to 0.
19 * @author Francois Chouinard
23 public class TmfSimpleTimestamp
extends TmfTimestamp
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
30 * Default constructor (value = 0)
32 public TmfSimpleTimestamp() {
39 * @param value the timestamp value
41 public TmfSimpleTimestamp(final long value
) {
48 * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
49 * scaled to seconds, and the precision will be discarded.
52 * The timestamp to copy
54 public TmfSimpleTimestamp(final ITmfTimestamp timestamp
) {
55 super(timestamp
.normalize(0, ITmfTimestamp
.SECOND_SCALE
).getValue(), 0, 0);
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
66 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
68 return new TmfSimpleTimestamp(getValue() + offset
);
70 return super.normalize(offset
, scale
);
74 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean)
77 public int compareTo(final ITmfTimestamp ts
, final boolean withinPrecision
) {
78 if (ts
instanceof TmfSimpleTimestamp
) {
79 final long delta
= getValue() - ts
.getValue();
80 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
82 return super.compareTo(ts
, withinPrecision
);
86 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
89 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
90 if (ts
instanceof TmfSimpleTimestamp
) {
91 return new TmfTimestampDelta(getValue() - ts
.getValue());
93 return super.getDelta(ts
);
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode()
104 public int hashCode() {
105 return super.hashCode();
109 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
112 public boolean equals(final Object other
) {
119 if (!(other
instanceof TmfSimpleTimestamp
)) {
120 return super.equals(other
);
122 final TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
124 return compareTo(ts
, false) == 0;
This page took 0.032773 seconds and 5 git commands to generate.