Revert "Fix for bug 381411: Implement ranked location in experiment."
[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 * A simplified timestamp where scale and precision are set to 0.
17 *
18 * @version 1.0
19 * @author Francois Chouinard
20 */
21 public class TmfSimpleTimestamp extends TmfTimestamp implements Cloneable {
22
23 // ------------------------------------------------------------------------
24 // Constructors
25 // ------------------------------------------------------------------------
26
27 /**
28 * Default constructor (value = 0)
29 */
30 public TmfSimpleTimestamp() {
31 this(0);
32 }
33
34 /**
35 * Full constructor
36 *
37 * @param value the timestamp value
38 */
39 public TmfSimpleTimestamp(final long value) {
40 super(value, 0, 0);
41 }
42
43 /**
44 * Copy constructor
45 *
46 * @param timestamp the timestamp to copy
47 */
48 public TmfSimpleTimestamp(final ITmfTimestamp timestamp) {
49 if (timestamp == null || timestamp.getScale() != 0 || timestamp.getPrecision() != 0) {
50 throw new IllegalArgumentException();
51 }
52 setValue(timestamp.getValue(), 0, 0);
53 }
54
55 // ------------------------------------------------------------------------
56 // ITmfTimestamp
57 // ------------------------------------------------------------------------
58
59 /* (non-Javadoc)
60 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
61 */
62 @Override
63 public ITmfTimestamp normalize(final long offset, final int scale) {
64 if (scale == 0) {
65 return new TmfSimpleTimestamp(getValue() + offset);
66 }
67 return super.normalize(offset, scale);
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean)
72 */
73 @Override
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;
78 }
79 return super.compareTo(ts, withinPrecision);
80 }
81
82 /* (non-Javadoc)
83 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
84 */
85 @Override
86 public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
87 if (ts instanceof TmfSimpleTimestamp) {
88 return new TmfSimpleTimestamp(getValue() - ts.getValue());
89 }
90 return super.getDelta(ts);
91 }
92
93 // ------------------------------------------------------------------------
94 // Cloneable
95 // ------------------------------------------------------------------------
96
97 /* (non-Javadoc)
98 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#clone()
99 */
100 @Override
101 public TmfSimpleTimestamp clone() {
102 return (TmfSimpleTimestamp) super.clone();
103 }
104
105 // ------------------------------------------------------------------------
106 // Object
107 // ------------------------------------------------------------------------
108
109 /* (non-Javadoc)
110 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode()
111 */
112 @Override
113 public int hashCode() {
114 return super.hashCode();
115 }
116
117 /* (non-Javadoc)
118 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
119 */
120 @Override
121 public boolean equals(final Object other) {
122 if (this == other) {
123 return true;
124 }
125 if (other == null) {
126 return false;
127 }
128 if (!(other instanceof TmfSimpleTimestamp)) {
129 return super.equals(other);
130 }
131 final TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
132
133 return compareTo(ts, false) == 0;
134 }
135
136 /* (non-Javadoc)
137 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString()
138 */
139 @Override
140 @SuppressWarnings("nls")
141 public String toString() {
142 return "TmfSimpleTimestamp [fValue=" + getValue() + "]";
143 }
144
145 }
This page took 0.034368 seconds and 5 git commands to generate.