Implement the new TMF Event Model
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfSimpleTimestamp.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.event;
14
15 /**
16 * <b><u>TmfSimpleTimestamp</u></b>
17 * <p>
18 * A simplified timestamp where scale and precision are set to 0.
19 */
20 public class TmfSimpleTimestamp extends TmfTimestamp {
21
22 // ------------------------------------------------------------------------
23 // Constructors
24 // ------------------------------------------------------------------------
25
26 /**
27 * Default constructor
28 */
29 public TmfSimpleTimestamp() {
30 this(0);
31 }
32
33 /**
34 * Full constructor
35 *
36 * @param value the timestamp value
37 */
38 public TmfSimpleTimestamp(long value) {
39 super(value, 0, 0);
40 }
41
42 /**
43 * Copy constructor
44 *
45 * @param timestamp the timestamp to copy
46 */
47 public TmfSimpleTimestamp(TmfSimpleTimestamp timestamp) {
48 if (timestamp == null || timestamp.getScale() != 0 || timestamp.getPrecision() != 0)
49 throw new IllegalArgumentException();
50 fValue = timestamp.getValue();
51 fScale = 0;
52 fPrecision = 0;
53 }
54
55 // ------------------------------------------------------------------------
56 // ITmfTimestamp
57 // ------------------------------------------------------------------------
58
59 @Override
60 public ITmfTimestamp normalize(long offset, int scale) throws ArithmeticException {
61 if (scale == 0) {
62 return new TmfSimpleTimestamp(fValue + offset);
63 }
64 return super.normalize(offset, scale);
65 }
66
67 @Override
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;
72 }
73 return super.compareTo(ts, withinPrecision);
74 }
75
76 @Override
77 public ITmfTimestamp getDelta(ITmfTimestamp ts) {
78 if (ts instanceof TmfSimpleTimestamp) {
79 return new TmfSimpleTimestamp(fValue - ts.getValue());
80 }
81 return super.getDelta(ts);
82 }
83
84 // ------------------------------------------------------------------------
85 // Object
86 // ------------------------------------------------------------------------
87
88 @Override
89 public boolean equals(Object other) {
90 if (this == other)
91 return true;
92 if (other == null)
93 return false;
94 if (!(other instanceof TmfSimpleTimestamp))
95 return super.equals(other);
96 TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
97 return compareTo(ts, false) == 0;
98 }
99
100 @Override
101 @SuppressWarnings("nls")
102 public String toString() {
103 return "TmfSimpleTimestamp [fValue=" + fValue + "]";
104 }
105
106 }
This page took 0.033967 seconds and 5 git commands to generate.