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>
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
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 variable-sized string
24 * @author Alexandre Montplaisir
26 final class StringStateValue
extends TmfStateValue
{
28 private final String value
;
30 public StringStateValue(String valueAsString
) {
31 this.value
= valueAsString
;
35 public Type
getType() {
40 public boolean isNull() {
45 public boolean equals(@Nullable Object object
) {
46 if (!(object
instanceof StringStateValue
)) {
49 StringStateValue other
= (StringStateValue
) object
;
50 return value
.equals(other
.value
);
54 public int hashCode() {
55 return value
.hashCode();
59 public String
toString() {
64 public byte[] serialize() {
65 byte[] strBytes
= value
.getBytes();
66 ByteBuffer buffer
= ByteBuffer
.allocate(Byte
.BYTES
+ strBytes
.length
);
67 buffer
.put(getType().getByte());
69 return buffer
.array();
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 public String
unboxStr() {
82 public int compareTo(@Nullable ITmfStateValue other
) {
84 throw new IllegalArgumentException();
87 switch (other
.getType()) {
89 throw new StateValueTypeException("A String state value cannot be compared to a Double state value."); //$NON-NLS-1$
91 throw new StateValueTypeException("A String state value cannot be compared to an Integer state value."); //$NON-NLS-1$
93 throw new StateValueTypeException("A String state value cannot be compared to a Long state value."); //$NON-NLS-1$
96 * We assume that every string state value is greater than a null
101 StringStateValue otherStringValue
= (StringStateValue
) other
;
102 return value
.compareTo(otherStringValue
.value
);
104 throw new StateValueTypeException("A String state value cannot be compared to the type " + other
.getType()); //$NON-NLS-1$