Revert "ss: Add serialization logic to state values"
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / statesystem / core / statevalue / DoubleStateValue.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
13 package org.eclipse.tracecompass.statesystem.core.statevalue;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
17
18 /**
19 * A state value containing a double primitive.
20 *
21 * @author Alexandre Montplaisir
22 */
23 final class DoubleStateValue extends TmfStateValue {
24
25 private final double value;
26
27 public DoubleStateValue(double value) {
28 this.value = value;
29 }
30
31 @Override
32 public Type getType() {
33 return Type.DOUBLE;
34 }
35
36 @Override
37 public boolean isNull() {
38 return false;
39 }
40
41 @Override
42 public boolean equals(@Nullable Object object) {
43 if (!(object instanceof DoubleStateValue)) {
44 return false;
45 }
46 DoubleStateValue other = (DoubleStateValue) object;
47 return (Double.compare(this.value, other.value) == 0);
48 }
49
50 @Override
51 public int hashCode() {
52 long bits = Double.doubleToLongBits(value);
53 return ((int) bits) ^ ((int) (bits >>> 32));
54 }
55
56 @Override
57 public @Nullable String toString() {
58 return String.format("%3f", value); //$NON-NLS-1$
59 }
60
61 // ------------------------------------------------------------------------
62 // Unboxing methods
63 // ------------------------------------------------------------------------
64
65 @Override
66 public double unboxDouble() {
67 return value;
68 }
69
70 @Override
71 public int compareTo(@Nullable ITmfStateValue other) {
72 if (other == null) {
73 throw new IllegalArgumentException();
74 }
75
76 switch (other.getType()) {
77 case INTEGER:
78 double otherDoubleValue = ((IntegerStateValue) other).unboxInt();
79 return Double.compare(this.value, otherDoubleValue);
80 case DOUBLE:
81 otherDoubleValue = ((DoubleStateValue) other).unboxDouble();
82 return Double.compare(this.value, otherDoubleValue);
83 case LONG:
84 otherDoubleValue = ((LongStateValue) other).unboxLong();
85 return Double.compare(this.value, otherDoubleValue);
86 case NULL:
87 return Double.compare(this.value, other.unboxDouble());
88 case STRING:
89 throw new StateValueTypeException("A Double state value cannot be compared to a String state value."); //$NON-NLS-1$
90 default:
91 throw new StateValueTypeException("A Double state value cannot be compared to the type " + other.getType()); //$NON-NLS-1$
92 }
93
94 }
95
96 }
This page took 0.051868 seconds and 5 git commands to generate.