1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
6 * All rights reserved. This program and the accompanying materials are
7 * made available under the terms of the Eclipse Public License v1.0 which
8 * accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
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 simple integer.
22 * @author Alexandre Montplaisir
24 final class IntegerStateValue
extends TmfStateValue
{
26 private final int value
;
28 public IntegerStateValue(int valueAsInt
) {
29 this.value
= valueAsInt
;
33 public Type
getType() {
38 public boolean isNull() {
43 public boolean equals(@Nullable Object object
) {
44 if (!(object
instanceof IntegerStateValue
)) {
47 IntegerStateValue other
= (IntegerStateValue
) object
;
48 return (this.value
== other
.value
);
52 public int hashCode() {
57 public @Nullable String
toString() {
58 return String
.format("%3d", value
); //$NON-NLS-1$
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
66 public int unboxInt() {
71 public long unboxLong() {
72 /* It's always safe to up-cast an int into a long */
77 public int compareTo(@Nullable ITmfStateValue other
) {
79 throw new IllegalArgumentException();
82 switch (other
.getType()) {
84 IntegerStateValue otherIntValue
= (IntegerStateValue
) other
;
85 return Integer
.compare(this.value
, otherIntValue
.value
);
87 double otherDoubleValue
= ((DoubleStateValue
) other
).unboxDouble();
88 return Double
.compare(this.value
, otherDoubleValue
);
90 long otherLongValue
= ((LongStateValue
) other
).unboxLong();
91 return Long
.compare(this.value
, otherLongValue
);
93 return Integer
.compare(this.value
, other
.unboxInt());
95 throw new StateValueTypeException("An Integer state value cannot be compared to a String state value."); //$NON-NLS-1$
97 throw new StateValueTypeException("An Integer state value cannot be compared to the type " + other
.getType()); //$NON-NLS-1$