1 /*******************************************************************************
2 * Copyright (c) 2012, 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 * Francois Chouinard - Standardize on the default toString()
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.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);
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
65 return new TmfSimpleTimestamp(getValue() + offset
);
67 return super.normalize(offset
, scale
);
71 public int compareTo(final ITmfTimestamp ts
) {
72 if (ts
instanceof TmfSimpleTimestamp
) {
73 final long delta
= getValue() - ts
.getValue();
74 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
76 return super.compareTo(ts
);
80 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
81 if (ts
instanceof TmfSimpleTimestamp
) {
82 return new TmfTimestampDelta(getValue() - ts
.getValue());
84 return super.getDelta(ts
);
87 // ------------------------------------------------------------------------
89 // ------------------------------------------------------------------------
92 public int hashCode() {
93 return super.hashCode();
97 public boolean equals(final Object other
) {
104 if (!(other
instanceof TmfSimpleTimestamp
)) {
105 return super.equals(other
);
107 final TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
109 return compareTo(ts
) == 0;
This page took 0.038642 seconds and 5 git commands to generate.