Commit | Line | Data |
---|---|---|
a52fde77 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
a52fde77 AM |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
2cb26548 | 5 | * |
a52fde77 AM |
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 | |
2cb26548 | 10 | * |
a52fde77 AM |
11 | *******************************************************************************/ |
12 | ||
e894a508 | 13 | package org.eclipse.tracecompass.statesystem.core.statevalue; |
a52fde77 | 14 | |
6f7e27a0 EB |
15 | import org.eclipse.jdt.annotation.Nullable; |
16 | ||
a52fde77 AM |
17 | /** |
18 | * A state value that contains no particular value. It is sometimes needed over | |
19 | * a "null" reference, since we avoid NPE's this way. | |
2cb26548 | 20 | * |
a52fde77 | 21 | * It can also be read either as a String ("nullValue") or an Integer (-1). |
a52fde77 | 22 | * |
2cb26548 AM |
23 | * @version 1.0 |
24 | * @author Alexandre Montplaisir | |
a52fde77 AM |
25 | */ |
26 | final class NullStateValue extends TmfStateValue { | |
27 | ||
77c2c2c9 AM |
28 | private final String value = "nullValue"; //$NON-NLS-1$ |
29 | ||
a52fde77 | 30 | @Override |
b67a2540 AM |
31 | public Type getType() { |
32 | return Type.NULL; | |
a52fde77 AM |
33 | } |
34 | ||
35 | @Override | |
36 | public boolean isNull() { | |
37 | return true; | |
38 | } | |
39 | ||
40 | @Override | |
6f7e27a0 EB |
41 | public boolean equals(@Nullable Object object) { |
42 | return (object instanceof NullStateValue); | |
43 | } | |
44 | ||
45 | @Override | |
46 | public int hashCode() { | |
f0247a1a | 47 | return 0; |
a52fde77 AM |
48 | } |
49 | ||
a52fde77 AM |
50 | @Override |
51 | public String toString() { | |
77c2c2c9 | 52 | return value; |
a52fde77 | 53 | } |
a9cdbafc AM |
54 | |
55 | // ------------------------------------------------------------------------ | |
56 | // Unboxing methods. Null values can be unboxed into any type. | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
59 | @Override | |
60 | public int unboxInt() { | |
61 | return -1; | |
62 | } | |
63 | ||
64 | @Override | |
65 | public long unboxLong() { | |
66 | return -1; | |
67 | } | |
68 | ||
a3c22e8e AM |
69 | @Override |
70 | public double unboxDouble() { | |
71 | return Double.NaN; | |
72 | } | |
73 | ||
a9cdbafc AM |
74 | @Override |
75 | public String unboxStr() { | |
6f7e27a0 | 76 | return value; |
a9cdbafc | 77 | } |
f0247a1a NE |
78 | |
79 | @Override | |
80 | public int compareTo(@Nullable ITmfStateValue other) { | |
81 | if (other == null) { | |
82 | throw new IllegalArgumentException(); | |
83 | } | |
84 | if (other instanceof NullStateValue) { | |
85 | return 0; | |
86 | } | |
87 | /* | |
88 | * For every other state value type, we defer to how that type wants to | |
89 | * be compared against null values. | |
90 | */ | |
91 | return -(other.compareTo(this)); | |
92 | } | |
93 | ||
a52fde77 | 94 | } |