Commit | Line | Data |
---|---|---|
a3c22e8e AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 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 | * Alexandre Montplaisir - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
bcec0116 | 13 | package org.eclipse.linuxtools.statesystem.core.statevalue; |
a3c22e8e | 14 | |
75d2d348 AM |
15 | import org.eclipse.jdt.annotation.Nullable; |
16 | ||
a3c22e8e AM |
17 | /** |
18 | * A state value containing a double primitive. | |
19 | * | |
20 | * @author Alexandre Montplaisir | |
21 | */ | |
22 | final class DoubleStateValue extends TmfStateValue { | |
23 | ||
6f7e27a0 | 24 | private final double value; |
a3c22e8e AM |
25 | |
26 | public DoubleStateValue(double value) { | |
6f7e27a0 | 27 | this.value = value; |
a3c22e8e AM |
28 | } |
29 | ||
30 | @Override | |
31 | public Type getType() { | |
ec5fec10 | 32 | return Type.DOUBLE; |
a3c22e8e AM |
33 | } |
34 | ||
35 | @Override | |
36 | public boolean isNull() { | |
37 | return false; | |
38 | } | |
39 | ||
40 | @Override | |
6f7e27a0 EB |
41 | public boolean equals(@Nullable Object object) { |
42 | if (!(object instanceof DoubleStateValue)) { | |
43 | return false; | |
44 | } | |
45 | DoubleStateValue other = (DoubleStateValue) object; | |
46 | return (Double.compare(this.value, other.value) == 0); | |
47 | } | |
48 | ||
49 | @Override | |
50 | public int hashCode() { | |
51 | long bits = Double.doubleToLongBits(value); | |
52 | return ((int) bits) ^ ((int) (bits >>> 32)); | |
a3c22e8e AM |
53 | } |
54 | ||
55 | @Override | |
75d2d348 | 56 | public @Nullable String toString() { |
6f7e27a0 | 57 | return String.format("%3f", value); //$NON-NLS-1$ |
a3c22e8e AM |
58 | } |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Unboxing methods | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
64 | @Override | |
65 | public double unboxDouble() { | |
6f7e27a0 | 66 | return value; |
a3c22e8e AM |
67 | } |
68 | } |