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