Commit | Line | Data |
---|---|---|
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 | ||
13 | package 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 | */ | |
20 | public 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 | */ | |
47 | public TmfSimpleTimestamp(TmfSimpleTimestamp timestamp) { | |
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 | ||
93 | // ------------------------------------------------------------------------ | |
94 | // Object | |
95 | // ------------------------------------------------------------------------ | |
96 | ||
d7dbf09a FC |
97 | /* (non-Javadoc) |
98 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object) | |
99 | */ | |
7636a88e | 100 | @Override |
101 | public boolean equals(Object other) { | |
102 | if (this == other) | |
103 | return true; | |
104 | if (other == null) | |
105 | return false; | |
106 | if (!(other instanceof TmfSimpleTimestamp)) | |
107 | return super.equals(other); | |
108 | TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other; | |
109 | return compareTo(ts, false) == 0; | |
110 | } | |
111 | ||
d7dbf09a FC |
112 | /* (non-Javadoc) |
113 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString() | |
114 | */ | |
7636a88e | 115 | @Override |
116 | @SuppressWarnings("nls") | |
117 | public String toString() { | |
4c564a2d | 118 | return "TmfSimpleTimestamp [fValue=" + fValue + "]"; |
7636a88e | 119 | } |
120 | ||
121 | } |