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 org
.eclipse
.jdt
.annotation
.Nullable
;
16 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
19 * A state value containing a variable-sized string
22 * @author Alexandre Montplaisir
24 final class StringStateValue
extends TmfStateValue
{
26 private final String value
;
28 public StringStateValue(String valueAsString
) {
29 this.value
= valueAsString
;
33 public Type
getType() {
38 public boolean isNull() {
43 public boolean equals(@Nullable Object object
) {
44 if (!(object
instanceof StringStateValue
)) {
47 StringStateValue other
= (StringStateValue
) object
;
48 return value
.equals(other
.value
);
52 public int hashCode() {
53 return value
.hashCode();
57 public String
toString() {
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
66 public String
unboxStr() {
71 public int compareTo(@Nullable ITmfStateValue other
) {
73 throw new IllegalArgumentException();
76 switch (other
.getType()) {
78 throw new StateValueTypeException("A String state value cannot be compared to a Double state value."); //$NON-NLS-1$
80 throw new StateValueTypeException("A String state value cannot be compared to an Integer state value."); //$NON-NLS-1$
82 throw new StateValueTypeException("A String state value cannot be compared to a Long state value."); //$NON-NLS-1$
85 * We assume that every string state value is greater than a null
90 StringStateValue otherStringValue
= (StringStateValue
) other
;
91 return value
.compareTo(otherStringValue
.value
);
93 throw new StateValueTypeException("A String state value cannot be compared to the type " + other
.getType()); //$NON-NLS-1$