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 * <b><u>TmfSimpleTimestamp</u></b>
18 * A simplified timestamp where scale and precision are set to 0.
20 public class TmfSimpleTimestamp
extends TmfTimestamp
{
22 // ------------------------------------------------------------------------
24 // ------------------------------------------------------------------------
29 public TmfSimpleTimestamp() {
36 * @param value the timestamp value
38 public TmfSimpleTimestamp(long value
) {
45 * @param timestamp the timestamp to copy
47 public TmfSimpleTimestamp(TmfSimpleTimestamp timestamp
) {
48 if (timestamp
== null || timestamp
.getScale() != 0 || timestamp
.getPrecision() != 0)
49 throw new IllegalArgumentException();
50 fValue
= timestamp
.getValue();
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 public ITmfTimestamp
normalize(long offset
, int scale
) throws ArithmeticException
{
62 return new TmfSimpleTimestamp(fValue
+ offset
);
64 return super.normalize(offset
, scale
);
68 public int compareTo(ITmfTimestamp ts
, boolean withinPrecision
) {
69 if (ts
instanceof TmfSimpleTimestamp
) {
70 long delta
= fValue
- ts
.getValue();
71 return (delta
== 0) ?
0 : (delta
> 0) ?
1 : -1;
73 return super.compareTo(ts
, withinPrecision
);
77 public ITmfTimestamp
getDelta(ITmfTimestamp ts
) {
78 if (ts
instanceof TmfSimpleTimestamp
) {
79 return new TmfSimpleTimestamp(fValue
- ts
.getValue());
81 return super.getDelta(ts
);
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 public boolean equals(Object other
) {
94 if (!(other
instanceof TmfSimpleTimestamp
))
95 return super.equals(other
);
96 TmfSimpleTimestamp ts
= (TmfSimpleTimestamp
) other
;
97 return compareTo(ts
, false) == 0;
101 @SuppressWarnings("nls")
102 public String
toString() {
103 return "TmfSimpleTimestamp [fValue=" + fValue
+ "]";