Fix version in LTTng's category.xml file
[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/**
16 * <b><u>TmfSimpleTimestamp</u></b>
17 * <p>
18 * A simplified timestamp where scale and precision are set to 0.
19 */
20public class TmfSimpleTimestamp extends TmfTimestamp {
21
22 // ------------------------------------------------------------------------
23 // Constructors
24 // ------------------------------------------------------------------------
25
26 /**
27 * Default constructor
28 */
29 public TmfSimpleTimestamp() {
30 this(0);
31 }
32
33 /**
34 * Full constructor
35 *
36 * @param value the timestamp value
37 */
38 public TmfSimpleTimestamp(long value) {
39 super(value, 0, 0);
40 }
41
42 /**
43 * Copy constructor
44 *
45 * @param timestamp the timestamp to copy
46 */
7656d70a 47 public TmfSimpleTimestamp(ITmfTimestamp timestamp) {
7636a88e 48 if (timestamp == null || timestamp.getScale() != 0 || timestamp.getPrecision() != 0)
49 throw new IllegalArgumentException();
50 fValue = timestamp.getValue();
51 fScale = 0;
52 fPrecision = 0;
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
63 public ITmfTimestamp normalize(long offset, int scale) throws ArithmeticException {
64 if (scale == 0) {
65 return new TmfSimpleTimestamp(fValue + offset);
66 }
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
74 public int compareTo(ITmfTimestamp ts, boolean withinPrecision) {
75 if (ts instanceof TmfSimpleTimestamp) {
76 long delta = fValue - ts.getValue();
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
86 public ITmfTimestamp getDelta(ITmfTimestamp ts) {
87 if (ts instanceof TmfSimpleTimestamp) {
88 return new TmfSimpleTimestamp(fValue - ts.getValue());
89 }
90 return super.getDelta(ts);
91 }
92
8c149234
FC
93 // ------------------------------------------------------------------------
94 // Cloneable
95 // ------------------------------------------------------------------------
96
97 /* (non-Javadoc)
98 * @see java.lang.Object#clone()
99 */
100 @Override
101 public TmfSimpleTimestamp clone() {
102 return (TmfSimpleTimestamp) super.clone();
103 }
104
7636a88e 105 // ------------------------------------------------------------------------
106 // Object
107 // ------------------------------------------------------------------------
108
d7dbf09a
FC
109 /* (non-Javadoc)
110 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object)
111 */
7636a88e 112 @Override
113 public boolean equals(Object other) {
114 if (this == other)
115 return true;
116 if (other == null)
117 return false;
118 if (!(other instanceof TmfSimpleTimestamp))
119 return super.equals(other);
120 TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
7656d70a 121
7636a88e 122 return compareTo(ts, false) == 0;
123 }
124
d7dbf09a
FC
125 /* (non-Javadoc)
126 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString()
127 */
7636a88e 128 @Override
129 @SuppressWarnings("nls")
130 public String toString() {
4c564a2d 131 return "TmfSimpleTimestamp [fValue=" + fValue + "]";
7636a88e 132 }
133
134}
This page took 0.029038 seconds and 5 git commands to generate.