1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
;
15 import org
.eclipse
.jdt
.annotation
.Nullable
;
16 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
19 * A state value containing a double primitive.
21 * @author Alexandre Montplaisir
23 final class DoubleStateValue
extends TmfStateValue
{
25 private final double value
;
27 public DoubleStateValue(double value
) {
32 public Type
getType() {
37 public boolean isNull() {
42 public boolean equals(@Nullable Object object
) {
43 if (!(object
instanceof DoubleStateValue
)) {
46 DoubleStateValue other
= (DoubleStateValue
) object
;
47 return (Double
.compare(this.value
, other
.value
) == 0);
51 public int hashCode() {
52 long bits
= Double
.doubleToLongBits(value
);
53 return ((int) bits
) ^
((int) (bits
>>> 32));
57 public @Nullable String
toString() {
58 return String
.format("%3f", value
); //$NON-NLS-1$
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
66 public double unboxDouble() {
71 public int compareTo(@Nullable ITmfStateValue other
) {
73 throw new IllegalArgumentException();
76 switch (other
.getType()) {
78 double otherDoubleValue
= ((IntegerStateValue
) other
).unboxInt();
79 return Double
.compare(this.value
, otherDoubleValue
);
81 otherDoubleValue
= ((DoubleStateValue
) other
).unboxDouble();
82 return Double
.compare(this.value
, otherDoubleValue
);
84 otherDoubleValue
= ((LongStateValue
) other
).unboxLong();
85 return Double
.compare(this.value
, otherDoubleValue
);
87 return Double
.compare(this.value
, other
.unboxDouble());
89 throw new StateValueTypeException("A Double state value cannot be compared to a String state value."); //$NON-NLS-1$
92 throw new StateValueTypeException("A Double state value cannot be compared to the type " + other
.getType()); //$NON-NLS-1$
This page took 0.059109 seconds and 6 git commands to generate.