0770024a133d99979f43d7b0a510abbe2171385f
[deliverable/tracecompass.git] / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / statesystem / core / statevalue / LongStateValue.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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 * François Rajotte - 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 long integer (8 bytes).
20 *
21 * @version 1.0
22 * @author François Rajotte
23 */
24 final class LongStateValue extends TmfStateValue {
25
26 private final long value;
27
28 public LongStateValue(long valueAsLong) {
29 this.value = valueAsLong;
30 }
31
32 @Override
33 public Type getType() {
34 return Type.LONG;
35 }
36
37 @Override
38 public boolean isNull() {
39 return false;
40 }
41
42 @Override
43 public boolean equals(@Nullable Object object) {
44 if (!(object instanceof LongStateValue)) {
45 return false;
46 }
47 LongStateValue other = (LongStateValue) object;
48 return (this.value == other.value);
49 }
50
51 @Override
52 public int hashCode() {
53 return ((int) value) ^ ((int) (value >>> 32));
54 }
55
56 @Override
57 public @Nullable String toString() {
58 return String.format("%3d", value); //$NON-NLS-1$
59 }
60
61 // ------------------------------------------------------------------------
62 // Unboxing methods
63 // ------------------------------------------------------------------------
64
65 @Override
66 public long unboxLong() {
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 long otherLongValue = ((IntegerStateValue) other).unboxInt();
79 return Long.compare(this.value, otherLongValue);
80 case DOUBLE:
81 double otherDoubleValue = ((DoubleStateValue) other).unboxDouble();
82 return Double.compare(this.value, otherDoubleValue);
83 case LONG:
84 otherLongValue = ((LongStateValue) other).unboxLong();
85 return Long.compare(this.value, otherLongValue);
86 case NULL:
87 return Long.compare(this.value, other.unboxLong());
88 case STRING:
89 throw new StateValueTypeException("A Long state value cannot be compared to a String state value."); //$NON-NLS-1$
90 default:
91 throw new StateValueTypeException("A Long state value cannot be compared to the type " + other.getType()); //$NON-NLS-1$
92 }
93
94 }
95
96 }
This page took 0.051896 seconds and 4 git commands to generate.