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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.event
;
16 * A simplified timestamp where scale and precision are set to 0.
19 * @author Francois Chouinard
21 public class TmfSimpleTimestamp
extends TmfTimestamp
implements Cloneable
{
23 // ------------------------------------------------------------------------
25 // ------------------------------------------------------------------------
28 * Default constructor (value = 0)
30 public TmfSimpleTimestamp() {
37 * @param value the timestamp value
39 public TmfSimpleTimestamp(final long value
) {
46 * @param timestamp the timestamp to copy
48 public TmfSimpleTimestamp(final ITmfTimestamp timestamp
) {
49 if (timestamp
== null || timestamp
.getScale() != 0 || timestamp
.getPrecision() != 0) {
50 throw new IllegalArgumentException();
52 setValue(timestamp
.getValue(), 0, 0);
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
63 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
65 return new TmfSimpleTimestamp(getValue() + offset
);
67 return super.normalize(offset
, scale
);
71 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean)
74 public int compareTo(final ITmfTimestamp ts
, final boolean withinPrecision
) {
75 if (ts
instanceof TmfSimpleTimestamp
) {
76 final long delta
= getValue() - ts
.getValue();
77 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
79 return super.compareTo(ts
, withinPrecision
);
83 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
86 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
87 if (ts
instanceof TmfSimpleTimestamp
) {
88 return new TmfSimpleTimestamp(getValue() - ts
.getValue());
90 return super.getDelta(ts
);
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#clone()
101 public TmfSimpleTimestamp
clone() {
102 return (TmfSimpleTimestamp
) super.clone();
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode()
113 public int hashCode() {
114 return super.hashCode();
118 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
121 public boolean equals(final Object other
) {
128 if (!(other
instanceof TmfSimpleTimestamp
)) {
129 return super.equals(other
);
131 final TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
133 return compareTo(ts
, false) == 0;
137 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString()
140 @SuppressWarnings("nls")
141 public String
toString() {
142 return "TmfSimpleTimestamp [fValue=" + getValue() + "]";
This page took 0.034019 seconds and 5 git commands to generate.