ss: Add serialization logic to state values
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / statesystem / core / statevalue / NullStateValue.java
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>
5 *
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
10 *
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.statesystem.core.statevalue;
14
15 import org.eclipse.jdt.annotation.Nullable;
16
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.
20 *
21 * It can also be read either as a String ("nullValue") or an Integer (-1).
22 *
23 * @version 1.0
24 * @author Alexandre Montplaisir
25 */
26 final class NullStateValue extends TmfStateValue {
27
28 private static final byte[] EMPTY_ARRAY = new byte[0];
29 private static final String STR_VALUE = "nullValue"; //$NON-NLS-1$
30
31 @Override
32 public Type getType() {
33 return Type.NULL;
34 }
35
36 @Override
37 public boolean isNull() {
38 return true;
39 }
40
41 @Override
42 public boolean equals(@Nullable Object object) {
43 return (object instanceof NullStateValue);
44 }
45
46 @Override
47 public int hashCode() {
48 return 0;
49 }
50
51 @Override
52 public String toString() {
53 return STR_VALUE;
54 }
55
56 @Override
57 public byte[] serialize() {
58 return EMPTY_ARRAY;
59 }
60
61 // ------------------------------------------------------------------------
62 // Unboxing methods. Null values can be unboxed into any type.
63 // ------------------------------------------------------------------------
64
65 @Override
66 public int unboxInt() {
67 return -1;
68 }
69
70 @Override
71 public long unboxLong() {
72 return -1;
73 }
74
75 @Override
76 public double unboxDouble() {
77 return Double.NaN;
78 }
79
80 @Override
81 public String unboxStr() {
82 return STR_VALUE;
83 }
84
85 @Override
86 public int compareTo(@Nullable ITmfStateValue other) {
87 if (other == null) {
88 throw new IllegalArgumentException();
89 }
90 if (other instanceof NullStateValue) {
91 return 0;
92 }
93 /*
94 * For every other state value type, we defer to how that type wants to
95 * be compared against null values.
96 */
97 return -(other.compareTo(this));
98 }
99 }
This page took 0.034659 seconds and 5 git commands to generate.