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