Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / timestamp / TmfSimpleTimestamp.java
CommitLineData
7636a88e 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2012, 2014 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
2bdf0193 14package org.eclipse.tracecompass.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
7636a88e 20 */
9b749023 21public class TmfSimpleTimestamp extends TmfTimestamp {
7636a88e 22
23 // ------------------------------------------------------------------------
24 // Constructors
25 // ------------------------------------------------------------------------
26
27 /**
f7703ed6 28 * Default constructor (value = 0)
7636a88e 29 */
30 public TmfSimpleTimestamp() {
31 this(0);
32 }
33
34 /**
35 * Full constructor
36 *
37 * @param value the timestamp value
38 */
085d898f 39 public TmfSimpleTimestamp(final long value) {
065cc19b 40 super(value, 0);
7636a88e 41 }
42
43 /**
4593bd5b 44 * Copy constructor.
9b749023 45 *
4593bd5b
AM
46 * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
47 * scaled to seconds, and the precision will be discarded.
48 *
49 * @param timestamp
50 * The timestamp to copy
7636a88e 51 */
085d898f 52 public TmfSimpleTimestamp(final ITmfTimestamp timestamp) {
065cc19b 53 super(timestamp.normalize(0, ITmfTimestamp.SECOND_SCALE).getValue(), 0);
7636a88e 54 }
55
56 // ------------------------------------------------------------------------
57 // ITmfTimestamp
58 // ------------------------------------------------------------------------
59
60 @Override
0316808c 61 public ITmfTimestamp normalize(final long offset, final int scale) {
b9e37ffd
FC
62 if (scale == 0) {
63 return new TmfSimpleTimestamp(getValue() + offset);
64 }
7636a88e 65 return super.normalize(offset, scale);
66 }
67
68 @Override
065cc19b 69 public int compareTo(final ITmfTimestamp ts) {
7636a88e 70 if (ts instanceof TmfSimpleTimestamp) {
b9e37ffd 71 final long delta = getValue() - ts.getValue();
7636a88e 72 return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
73 }
065cc19b 74 return super.compareTo(ts);
7636a88e 75 }
76
77 @Override
085d898f 78 public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
b9e37ffd 79 if (ts instanceof TmfSimpleTimestamp) {
a9ee1687 80 return new TmfTimestampDelta(getValue() - ts.getValue());
b9e37ffd 81 }
7636a88e 82 return super.getDelta(ts);
83 }
84
85 // ------------------------------------------------------------------------
86 // Object
87 // ------------------------------------------------------------------------
88
beae214a
FC
89 @Override
90 public int hashCode() {
91 return super.hashCode();
92 }
93
7636a88e 94 @Override
085d898f 95 public boolean equals(final Object other) {
b9e37ffd 96 if (this == other) {
7636a88e 97 return true;
b9e37ffd
FC
98 }
99 if (other == null) {
7636a88e 100 return false;
b9e37ffd
FC
101 }
102 if (!(other instanceof TmfSimpleTimestamp)) {
7636a88e 103 return super.equals(other);
b9e37ffd 104 }
085d898f 105 final TmfSimpleTimestamp ts = (TmfSimpleTimestamp) other;
7656d70a 106
065cc19b 107 return compareTo(ts) == 0;
7636a88e 108 }
109
7636a88e 110}
This page took 0.095345 seconds and 5 git commands to generate.