Add null-checks for Map.get()
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / timestamp / TmfNanoTimestamp.java
CommitLineData
16035098 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 Ericsson
16035098
PT
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 * Patrick Tasse - Modified from TmfSimpleTimestamp to use nanosecond scale
12 *******************************************************************************/
13
2bdf0193 14package org.eclipse.tracecompass.tmf.core.timestamp;
16035098
PT
15
16/**
17 * A simplified timestamp where scale is nanoseconds and precision is set to 0.
16035098
PT
18 */
19public class TmfNanoTimestamp extends TmfTimestamp {
20
21 // ------------------------------------------------------------------------
22 // Constructors
23 // ------------------------------------------------------------------------
24
25 /**
26 * Default constructor (value = 0)
27 */
28 public TmfNanoTimestamp() {
29 this(0);
30 }
31
32 /**
33 * Full constructor
34 *
35 * @param value the timestamp value
36 */
37 public TmfNanoTimestamp(final long value) {
065cc19b 38 super(value, ITmfTimestamp.NANOSECOND_SCALE);
16035098
PT
39 }
40
41 /**
42 * Copy constructor.
43 *
44 * If the parameter is not a TmfNanoTimestamp, the timestamp will be
45 * scaled to nanoseconds, and the precision will be discarded.
46 *
47 * @param timestamp
48 * The timestamp to copy
49 */
50 public TmfNanoTimestamp(final ITmfTimestamp timestamp) {
065cc19b 51 super(timestamp.normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(), ITmfTimestamp.NANOSECOND_SCALE);
16035098
PT
52 }
53
54 // ------------------------------------------------------------------------
55 // ITmfTimestamp
56 // ------------------------------------------------------------------------
57
58 @Override
59 public ITmfTimestamp normalize(final long offset, final int scale) {
60 if (scale == ITmfTimestamp.NANOSECOND_SCALE) {
61 return new TmfNanoTimestamp(getValue() + offset);
62 }
63 return super.normalize(offset, scale);
64 }
65
66 @Override
065cc19b 67 public int compareTo(final ITmfTimestamp ts) {
16035098
PT
68 if (ts instanceof TmfNanoTimestamp) {
69 final long delta = getValue() - ts.getValue();
70 return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
71 }
065cc19b 72 return super.compareTo(ts);
16035098
PT
73 }
74
75 @Override
76 public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
77 if (ts instanceof TmfNanoTimestamp) {
78 return new TmfTimestampDelta(getValue() - ts.getValue(), ITmfTimestamp.NANOSECOND_SCALE);
79 }
80 return super.getDelta(ts);
81 }
82
83 // ------------------------------------------------------------------------
84 // Object
85 // ------------------------------------------------------------------------
86
87 @Override
88 public int hashCode() {
89 return super.hashCode();
90 }
91
92 @Override
93 public boolean equals(final Object other) {
94 if (this == other) {
95 return true;
96 }
97 if (other == null) {
98 return false;
99 }
100 if (!(other instanceof TmfNanoTimestamp)) {
101 return super.equals(other);
102 }
103 final TmfNanoTimestamp ts = (TmfNanoTimestamp) other;
104
065cc19b 105 return compareTo(ts) == 0;
16035098
PT
106 }
107
108}
This page took 0.072553 seconds and 5 git commands to generate.