1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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 * Patrick Tasse - Modified from TmfSimpleTimestamp to use nanosecond scale
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.timestamp
;
17 * A simplified timestamp where scale is nanoseconds and precision is set to 0.
19 public class TmfNanoTimestamp
extends TmfTimestamp
{
21 // ------------------------------------------------------------------------
23 // ------------------------------------------------------------------------
26 * Default constructor (value = 0)
28 public TmfNanoTimestamp() {
35 * @param value the timestamp value
37 public TmfNanoTimestamp(final long value
) {
38 super(value
, ITmfTimestamp
.NANOSECOND_SCALE
);
44 * If the parameter is not a TmfNanoTimestamp, the timestamp will be
45 * scaled to nanoseconds, and the precision will be discarded.
48 * The timestamp to copy
50 public TmfNanoTimestamp(final ITmfTimestamp timestamp
) {
51 super(timestamp
.normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue(), ITmfTimestamp
.NANOSECOND_SCALE
);
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
60 if (scale
== ITmfTimestamp
.NANOSECOND_SCALE
) {
61 return new TmfNanoTimestamp(getValue() + offset
);
63 return super.normalize(offset
, scale
);
67 public int compareTo(final ITmfTimestamp ts
) {
68 if (ts
instanceof TmfNanoTimestamp
) {
69 final long delta
= getValue() - ts
.getValue();
70 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
72 return super.compareTo(ts
);
76 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
77 if (ts
instanceof TmfNanoTimestamp
) {
78 return new TmfTimestampDelta(getValue() - ts
.getValue(), ITmfTimestamp
.NANOSECOND_SCALE
);
80 return super.getDelta(ts
);
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 public int hashCode() {
89 return super.hashCode();
93 public boolean equals(final Object other
) {
100 if (!(other
instanceof TmfNanoTimestamp
)) {
101 return super.equals(other
);
103 final TmfNanoTimestamp ts
= (TmfNanoTimestamp
) other
;
105 return compareTo(ts
) == 0;
This page took 0.035126 seconds and 5 git commands to generate.