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 i.e. timestamps
17 * are represented by the tuple { value, 0, 0 }.
21 * @author Francois Chouinard
25 public class TmfSimpleTimestamp
extends TmfTimestamp
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
34 public TmfSimpleTimestamp() {
41 * @param value the timestamp value
43 public TmfSimpleTimestamp(final long value
) {
50 * @param timestamp the timestamp to copy
52 public TmfSimpleTimestamp(final ITmfTimestamp timestamp
) {
53 if (timestamp
== null || timestamp
.getScale() != 0 || timestamp
.getPrecision() != 0) {
54 throw new IllegalArgumentException();
56 setValue(timestamp
.getValue(), 0, 0);
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
67 public ITmfTimestamp
normalize(final long offset
, final int scale
) throws ArithmeticException
{
69 return new TmfSimpleTimestamp(getValue() + offset
);
71 return super.normalize(offset
, scale
);
75 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean)
78 public int compareTo(final ITmfTimestamp ts
, final boolean withinPrecision
) {
79 if (ts
instanceof TmfSimpleTimestamp
) {
80 final long delta
= getValue() - ts
.getValue();
81 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
83 return super.compareTo(ts
, withinPrecision
);
87 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
90 public ITmfTimestamp
getDelta(final ITmfTimestamp ts
) {
91 if (ts
instanceof TmfSimpleTimestamp
) {
92 return new TmfSimpleTimestamp(getValue() - ts
.getValue());
94 return super.getDelta(ts
);
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
102 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#clone()
105 public TmfSimpleTimestamp
clone() {
106 return (TmfSimpleTimestamp
) super.clone();
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
114 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode()
117 public int hashCode() {
118 return super.hashCode();
122 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
125 public boolean equals(final Object other
) {
132 if (!(other
instanceof TmfSimpleTimestamp
)) {
133 return super.equals(other
);
135 final TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
137 return compareTo(ts
, false) == 0;
141 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString()
144 @SuppressWarnings("nls")
145 public String
toString() {
146 return "TmfSimpleTimestamp [fValue=" + getValue() + "]";
This page took 0.03274 seconds and 5 git commands to generate.