tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / linuxtools / tmf / core / timestamp / TmfSimpleTimestamp.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Francois Chouinard - Standardize on the default toString()
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.timestamp;
15
16 /**
17 * A simplified timestamp where scale and precision are set to 0.
18 *
19 * @author Francois Chouinard
20 * @version 1.1
21 * @since 2.0
22 */
23 public class TmfSimpleTimestamp extends TmfTimestamp {
24
25 // ------------------------------------------------------------------------
26 // Constructors
27 // ------------------------------------------------------------------------
28
29 /**
30 * Default constructor (value = 0)
31 */
32 public TmfSimpleTimestamp() {
33 this(0);
34 }
35
36 /**
37 * Full constructor
38 *
39 * @param value the timestamp value
40 */
41 public TmfSimpleTimestamp(final long value) {
42 super(value, 0, 0);
43 }
44
45 /**
46 * Copy constructor.
47 *
48 * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
49 * scaled to seconds, and the precision will be discarded.
50 *
51 * @param timestamp
52 * The timestamp to copy
53 */
54 public TmfSimpleTimestamp(final ITmfTimestamp timestamp) {
55 super(timestamp.normalize(0, ITmfTimestamp.SECOND_SCALE).getValue(), 0, 0);
56 }
57
58 // ------------------------------------------------------------------------
59 // ITmfTimestamp
60 // ------------------------------------------------------------------------
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 @Override
71 public int compareTo(final ITmfTimestamp ts, final boolean withinPrecision) {
72 if (ts instanceof TmfSimpleTimestamp) {
73 final long delta = getValue() - ts.getValue();
74 return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
75 }
76 return super.compareTo(ts, withinPrecision);
77 }
78
79 @Override
80 public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
81 if (ts instanceof TmfSimpleTimestamp) {
82 return new TmfTimestampDelta(getValue() - ts.getValue());
83 }
84 return super.getDelta(ts);
85 }
86
87 // ------------------------------------------------------------------------
88 // Object
89 // ------------------------------------------------------------------------
90
91 @Override
92 public int hashCode() {
93 return super.hashCode();
94 }
95
96 @Override
97 public boolean equals(final Object other) {
98 if (this == other) {
99 return true;
100 }
101 if (other == null) {
102 return false;
103 }
104 if (!(other instanceof TmfSimpleTimestamp)) {
105 return super.equals(other);
106 }
107 final TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
108
109 return compareTo(ts, false) == 0;
110 }
111
112 }
This page took 0.040477 seconds and 5 git commands to generate.