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() {
38 public TmfNanoTimestamp(final long value
) {
39 super(value
, ITmfTimestamp
.NANOSECOND_SCALE
);
45 * If the parameter is not a TmfNanoTimestamp, the timestamp will be scaled
46 * to nanoseconds, and the precision will be discarded.
49 * The timestamp to copy
51 public TmfNanoTimestamp(final ITmfTimestamp timestamp
) {
52 super(timestamp
.toNanos(), ITmfTimestamp
.NANOSECOND_SCALE
);
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
61 if (scale
== ITmfTimestamp
.NANOSECOND_SCALE
) {
62 return new TmfNanoTimestamp(getValue() + offset
);
64 return super.normalize(offset
, scale
);
68 public int compareTo(final ITmfTimestamp ts
) {
69 if (ts
instanceof TmfNanoTimestamp
) {
70 final long delta
= getValue() - ts
.getValue();
71 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
73 return super.compareTo(ts
);
77 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
78 if (ts
instanceof TmfNanoTimestamp
) {
79 return new TmfTimestampDelta(getValue() - ts
.getValue(), ITmfTimestamp
.NANOSECOND_SCALE
);
81 return super.getDelta(ts
);
88 public long toNanos(){
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 public int hashCode() {
98 return super.hashCode();
102 public boolean equals(final Object other
) {
109 if (!(other
instanceof TmfNanoTimestamp
)) {
110 return super.equals(other
);
112 final TmfNanoTimestamp ts
= (TmfNanoTimestamp
) other
;
114 return compareTo(ts
) == 0;
This page took 0.032832 seconds and 5 git commands to generate.