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
21 public class TmfSimpleTimestamp
extends TmfTimestamp
{
23 // ------------------------------------------------------------------------
25 // ------------------------------------------------------------------------
28 * Default constructor (value = 0)
30 public TmfSimpleTimestamp() {
37 * @param value the timestamp value
39 public TmfSimpleTimestamp(final long value
) {
46 * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
47 * scaled to seconds, and the precision will be discarded.
50 * The timestamp to copy
52 public TmfSimpleTimestamp(final ITmfTimestamp timestamp
) {
53 super(timestamp
.normalize(0, ITmfTimestamp
.SECOND_SCALE
).getValue(), 0);
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
63 return new TmfSimpleTimestamp(getValue() + offset
);
65 return super.normalize(offset
, scale
);
69 public int compareTo(final ITmfTimestamp ts
) {
70 if (ts
instanceof TmfSimpleTimestamp
) {
71 final long delta
= getValue() - ts
.getValue();
72 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
74 return super.compareTo(ts
);
78 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
79 if (ts
instanceof TmfSimpleTimestamp
) {
80 return new TmfTimestampDelta(getValue() - ts
.getValue());
82 return super.getDelta(ts
);
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
90 public int hashCode() {
91 return super.hashCode();
95 public boolean equals(final Object other
) {
102 if (!(other
instanceof TmfSimpleTimestamp
)) {
103 return super.equals(other
);
105 final TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
107 return compareTo(ts
) == 0;
This page took 0.031755 seconds and 5 git commands to generate.