dae703845a8e4fb271b098cec5be9199e25ae2b5
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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 * François Rajotte - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
;
15 import java
.nio
.ByteBuffer
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
21 * A state value containing a long integer (8 bytes).
24 * @author François Rajotte
26 final class LongStateValue
extends TmfStateValue
{
28 private final long value
;
30 public LongStateValue(long valueAsLong
) {
31 this.value
= valueAsLong
;
35 public Type
getType() {
40 public boolean isNull() {
45 public boolean equals(@Nullable Object object
) {
46 if (!(object
instanceof LongStateValue
)) {
49 LongStateValue other
= (LongStateValue
) object
;
50 return (this.value
== other
.value
);
54 public int hashCode() {
55 return ((int) value
) ^
((int) (value
>>> 32));
59 public @Nullable String
toString() {
60 return String
.format("%3d", value
); //$NON-NLS-1$
64 public byte[] serialize() {
65 ByteBuffer buffer
= ByteBuffer
.allocate(Byte
.BYTES
+ Long
.BYTES
);
66 buffer
.put(getType().getByte());
67 buffer
.putLong(value
);
68 return buffer
.array();
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 public long unboxLong() {
81 public int compareTo(@Nullable ITmfStateValue other
) {
83 throw new IllegalArgumentException();
86 switch (other
.getType()) {
88 long otherLongValue
= ((IntegerStateValue
) other
).unboxInt();
89 return Long
.compare(this.value
, otherLongValue
);
91 double otherDoubleValue
= ((DoubleStateValue
) other
).unboxDouble();
92 return Double
.compare(this.value
, otherDoubleValue
);
94 otherLongValue
= ((LongStateValue
) other
).unboxLong();
95 return Long
.compare(this.value
, otherLongValue
);
97 return Long
.compare(this.value
, other
.unboxLong());
99 throw new StateValueTypeException("A Long state value cannot be compared to a String state value."); //$NON-NLS-1$
101 throw new StateValueTypeException("A Long state value cannot be compared to the type " + other
.getType()); //$NON-NLS-1$
This page took 0.048323 seconds and 4 git commands to generate.