Commit | Line | Data |
---|---|---|
7636a88e | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2012, 2013 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 | |
f8177ba2 | 11 | * Francois Chouinard - Standardize on the default toString() |
7636a88e | 12 | *******************************************************************************/ |
13 | ||
3bd46eef | 14 | package org.eclipse.linuxtools.tmf.core.timestamp; |
7636a88e | 15 | |
16 | /** | |
2848c377 | 17 | * A simplified timestamp where scale and precision are set to 0. |
9b749023 | 18 | * |
b9e37ffd | 19 | * @author Francois Chouinard |
3bd46eef AM |
20 | * @version 1.1 |
21 | * @since 2.0 | |
7636a88e | 22 | */ |
9b749023 | 23 | public class TmfSimpleTimestamp extends TmfTimestamp { |
7636a88e | 24 | |
25 | // ------------------------------------------------------------------------ | |
26 | // Constructors | |
27 | // ------------------------------------------------------------------------ | |
28 | ||
29 | /** | |
f7703ed6 | 30 | * Default constructor (value = 0) |
7636a88e | 31 | */ |
32 | public TmfSimpleTimestamp() { | |
33 | this(0); | |
34 | } | |
35 | ||
36 | /** | |
37 | * Full constructor | |
38 | * | |
39 | * @param value the timestamp value | |
40 | */ | |
085d898f | 41 | public TmfSimpleTimestamp(final long value) { |
7636a88e | 42 | super(value, 0, 0); |
43 | } | |
44 | ||
45 | /** | |
4593bd5b | 46 | * Copy constructor. |
9b749023 | 47 | * |
4593bd5b AM |
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 | |
7636a88e | 53 | */ |
085d898f | 54 | public TmfSimpleTimestamp(final ITmfTimestamp timestamp) { |
4593bd5b | 55 | super(timestamp.normalize(0, ITmfTimestamp.SECOND_SCALE).getValue(), 0, 0); |
7636a88e | 56 | } |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // ITmfTimestamp | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
d7dbf09a FC |
62 | /* (non-Javadoc) |
63 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int) | |
64 | */ | |
7636a88e | 65 | @Override |
0316808c | 66 | public ITmfTimestamp normalize(final long offset, final int scale) { |
b9e37ffd FC |
67 | if (scale == 0) { |
68 | return new TmfSimpleTimestamp(getValue() + offset); | |
69 | } | |
7636a88e | 70 | return super.normalize(offset, scale); |
71 | } | |
72 | ||
d7dbf09a FC |
73 | /* (non-Javadoc) |
74 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#compareTo(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp, boolean) | |
75 | */ | |
7636a88e | 76 | @Override |
085d898f | 77 | public int compareTo(final ITmfTimestamp ts, final boolean withinPrecision) { |
7636a88e | 78 | if (ts instanceof TmfSimpleTimestamp) { |
b9e37ffd | 79 | final long delta = getValue() - ts.getValue(); |
7636a88e | 80 | return (delta == 0) ? 0 : (delta > 0) ? 1 : -1; |
81 | } | |
82 | return super.compareTo(ts, withinPrecision); | |
83 | } | |
84 | ||
d7dbf09a FC |
85 | /* (non-Javadoc) |
86 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp) | |
87 | */ | |
7636a88e | 88 | @Override |
085d898f | 89 | public ITmfTimestamp getDelta(final ITmfTimestamp ts) { |
b9e37ffd | 90 | if (ts instanceof TmfSimpleTimestamp) { |
a9ee1687 | 91 | return new TmfTimestampDelta(getValue() - ts.getValue()); |
b9e37ffd | 92 | } |
7636a88e | 93 | return super.getDelta(ts); |
94 | } | |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // Object | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
beae214a FC |
100 | /* (non-Javadoc) |
101 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#hashCode() | |
102 | */ | |
103 | @Override | |
104 | public int hashCode() { | |
105 | return super.hashCode(); | |
106 | } | |
107 | ||
d7dbf09a FC |
108 | /* (non-Javadoc) |
109 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#equals(java.lang.Object) | |
110 | */ | |
7636a88e | 111 | @Override |
085d898f | 112 | public boolean equals(final Object other) { |
b9e37ffd | 113 | if (this == other) { |
7636a88e | 114 | return true; |
b9e37ffd FC |
115 | } |
116 | if (other == null) { | |
7636a88e | 117 | return false; |
b9e37ffd FC |
118 | } |
119 | if (!(other instanceof TmfSimpleTimestamp)) { | |
7636a88e | 120 | return super.equals(other); |
b9e37ffd | 121 | } |
085d898f | 122 | final TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other; |
7656d70a | 123 | |
7636a88e | 124 | return compareTo(ts, false) == 0; |
125 | } | |
126 | ||
7636a88e | 127 | } |