Commit | Line | Data |
---|---|---|
1cbf1a19 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
1cbf1a19 FR |
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 | ||
e894a508 | 13 | package org.eclipse.tracecompass.statesystem.core.statevalue; |
1cbf1a19 | 14 | |
77c2c2c9 | 15 | import org.eclipse.jdt.annotation.Nullable; |
f0247a1a | 16 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; |
77c2c2c9 | 17 | |
1cbf1a19 FR |
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 | ||
6f7e27a0 | 26 | private final long value; |
1cbf1a19 FR |
27 | |
28 | public LongStateValue(long valueAsLong) { | |
6f7e27a0 | 29 | this.value = valueAsLong; |
1cbf1a19 FR |
30 | } |
31 | ||
32 | @Override | |
33 | public Type getType() { | |
34 | return Type.LONG; | |
35 | } | |
36 | ||
37 | @Override | |
38 | public boolean isNull() { | |
39 | return false; | |
40 | } | |
f0247a1a | 41 | |
6f7e27a0 EB |
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 | } | |
1cbf1a19 FR |
50 | |
51 | @Override | |
6f7e27a0 EB |
52 | public int hashCode() { |
53 | return ((int) value) ^ ((int) (value >>> 32)); | |
1cbf1a19 FR |
54 | } |
55 | ||
1cbf1a19 | 56 | @Override |
77c2c2c9 | 57 | public @Nullable String toString() { |
6f7e27a0 | 58 | return String.format("%3d", value); //$NON-NLS-1$ |
1cbf1a19 | 59 | } |
a9cdbafc AM |
60 | |
61 | // ------------------------------------------------------------------------ | |
62 | // Unboxing methods | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | @Override | |
66 | public long unboxLong() { | |
6f7e27a0 | 67 | return value; |
a9cdbafc | 68 | } |
f0247a1a NE |
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 | ||
1cbf1a19 | 96 | } |