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
.event
;
17 * A simplified timestamp where scale and precision are set to 0.
20 * @author Francois Chouinard
22 public class TmfSimpleTimestamp
extends TmfTimestamp
{
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
29 * Default constructor (value = 0)
31 public TmfSimpleTimestamp() {
38 * @param value the timestamp value
40 public TmfSimpleTimestamp(final long value
) {
47 * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
48 * scaled to seconds, and the precision will be discarded.
51 * The timestamp to copy
53 public TmfSimpleTimestamp(final ITmfTimestamp timestamp
) {
54 super(timestamp
.normalize(0, ITmfTimestamp
.SECOND_SCALE
).getValue(), 0, 0);
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
62 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
65 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
67 return new TmfSimpleTimestamp(getValue() + offset
);
69 return super.normalize(offset
, scale
);
73 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean)
76 public int compareTo(final ITmfTimestamp ts
, final boolean withinPrecision
) {
77 if (ts
instanceof TmfSimpleTimestamp
) {
78 final long delta
= getValue() - ts
.getValue();
79 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
81 return super.compareTo(ts
, withinPrecision
);
85 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
88 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
89 if (ts
instanceof TmfSimpleTimestamp
) {
90 return new TmfTimestampDelta(getValue() - ts
.getValue());
92 return super.getDelta(ts
);
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode()
103 public int hashCode() {
104 return super.hashCode();
108 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
111 public boolean equals(final Object other
) {
118 if (!(other
instanceof TmfSimpleTimestamp
)) {
119 return super.equals(other
);
121 final TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
123 return compareTo(ts
, false) == 0;
This page took 0.03199 seconds and 5 git commands to generate.