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 | ||
62 | @Override | |
0316808c | 63 | public ITmfTimestamp normalize(final long offset, final int scale) { |
b9e37ffd FC |
64 | if (scale == 0) { |
65 | return new TmfSimpleTimestamp(getValue() + offset); | |
66 | } | |
7636a88e | 67 | return super.normalize(offset, scale); |
68 | } | |
69 | ||
70 | @Override | |
085d898f | 71 | public int compareTo(final ITmfTimestamp ts, final boolean withinPrecision) { |
7636a88e | 72 | if (ts instanceof TmfSimpleTimestamp) { |
b9e37ffd | 73 | final long delta = getValue() - ts.getValue(); |
7636a88e | 74 | return (delta == 0) ? 0 : (delta > 0) ? 1 : -1; |
75 | } | |
76 | return super.compareTo(ts, withinPrecision); | |
77 | } | |
78 | ||
79 | @Override | |
085d898f | 80 | public ITmfTimestamp getDelta(final ITmfTimestamp ts) { |
b9e37ffd | 81 | if (ts instanceof TmfSimpleTimestamp) { |
a9ee1687 | 82 | return new TmfTimestampDelta(getValue() - ts.getValue()); |
b9e37ffd | 83 | } |
7636a88e | 84 | return super.getDelta(ts); |
85 | } | |
86 | ||
87 | // ------------------------------------------------------------------------ | |
88 | // Object | |
89 | // ------------------------------------------------------------------------ | |
90 | ||
beae214a FC |
91 | @Override |
92 | public int hashCode() { | |
93 | return super.hashCode(); | |
94 | } | |
95 | ||
7636a88e | 96 | @Override |
085d898f | 97 | public boolean equals(final Object other) { |
b9e37ffd | 98 | if (this == other) { |
7636a88e | 99 | return true; |
b9e37ffd FC |
100 | } |
101 | if (other == null) { | |
7636a88e | 102 | return false; |
b9e37ffd FC |
103 | } |
104 | if (!(other instanceof TmfSimpleTimestamp)) { | |
7636a88e | 105 | return super.equals(other); |
b9e37ffd | 106 | } |
085d898f | 107 | final TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other; |
7656d70a | 108 | |
7636a88e | 109 | return compareTo(ts, false) == 0; |
110 | } | |
111 | ||
7636a88e | 112 | } |