Update to session creation procedure
[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 * Francois Chouinard - Standardize on the default toString()
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.event;
15
16 /**
17 * A simplified timestamp where scale and precision are set to 0.
18 *
19 * @version 1.1
20 * @author Francois Chouinard
21 */
22 public class TmfSimpleTimestamp extends TmfTimestamp {
23
24 // ------------------------------------------------------------------------
25 // Constructors
26 // ------------------------------------------------------------------------
27
28 /**
29 * Default constructor (value = 0)
30 */
31 public TmfSimpleTimestamp() {
32 this(0);
33 }
34
35 /**
36 * Full constructor
37 *
38 * @param value the timestamp value
39 */
40 public TmfSimpleTimestamp(final long value) {
41 super(value, 0, 0);
42 }
43
44 /**
45 * Copy constructor.
46 *
47 * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
48 * scaled to seconds, and the precision will be discarded.
49 *
50 * @param timestamp
51 * The timestamp to copy
52 */
53 public TmfSimpleTimestamp(final ITmfTimestamp timestamp) {
54 super(timestamp.normalize(0, ITmfTimestamp.SECOND_SCALE).getValue(), 0, 0);
55 }
56
57 // ------------------------------------------------------------------------
58 // ITmfTimestamp
59 // ------------------------------------------------------------------------
60
61 /* (non-Javadoc)
62 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
63 */
64 @Override
65 public ITmfTimestamp normalize(final long offset, final int scale) {
66 if (scale == 0) {
67 return new TmfSimpleTimestamp(getValue() + offset);
68 }
69 return super.normalize(offset, scale);
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean)
74 */
75 @Override
76 public int compareTo(final ITmfTimestamp ts, final boolean withinPrecision) {
77 if (ts instanceof TmfSimpleTimestamp) {
78 final long delta = getValue() - ts.getValue();
79 return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
80 }
81 return super.compareTo(ts, withinPrecision);
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
86 */
87 @Override
88 public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
89 if (ts instanceof TmfSimpleTimestamp) {
90 return new TmfTimestampDelta(getValue() - ts.getValue());
91 }
92 return super.getDelta(ts);
93 }
94
95 // ------------------------------------------------------------------------
96 // Object
97 // ------------------------------------------------------------------------
98
99 /* (non-Javadoc)
100 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode()
101 */
102 @Override
103 public int hashCode() {
104 return super.hashCode();
105 }
106
107 /* (non-Javadoc)
108 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
109 */
110 @Override
111 public boolean equals(final Object other) {
112 if (this == other) {
113 return true;
114 }
115 if (other == null) {
116 return false;
117 }
118 if (!(other instanceof TmfSimpleTimestamp)) {
119 return super.equals(other);
120 }
121 final TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
122
123 return compareTo(ts, false) == 0;
124 }
125
126 }
This page took 0.03199 seconds and 5 git commands to generate.