case LONG:
writer.println("TmfStateValue.newValueLong(" + val.unboxLong() +"),");
break;
+ case DOUBLE:
+ writer.println("TmfStateValue.newValueDouble(" + val.unboxDouble() +"),");
+ break;
case STRING:
writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),");
break;
private static final byte TYPE_INTEGER = 0;
private static final byte TYPE_STRING = 1;
private static final byte TYPE_LONG = 2;
+ private static final byte TYPE_DOUBLE = 3;
/* String entry sizes of different state values */
private static final int NO_ENTRY_SIZE = 0;
private static final int LONG_ENTRY_SIZE = 8;
+ private static final int DOUBLE_ENTRY_SIZE = 8;
// sizes of string values depend on the string itself
private final long start;
*/
buffer.reset();
break;
+
+ case TYPE_DOUBLE:
+ /* Go read the matching entry in the Strings section of the block */
+ buffer.mark();
+ buffer.position(valueOrOffset);
+ value = TmfStateValue.newValueDouble(buffer.getDouble());
+ valueSize = DOUBLE_ENTRY_SIZE;
+
+ /*
+ * Restore the file pointer's position (so we can read the next
+ * interval)
+ */
+ buffer.reset();
+ break;
+
default:
/* Unknown data, better to not make anything up... */
throw new IOException(errMsg);
buffer.reset();
break;
+ case TYPE_DOUBLE:
+ /* we use the valueOffset as an offset. */
+ buffer.putInt(endPosOfStringEntry - stringsEntrySize);
+ buffer.mark();
+ buffer.position(endPosOfStringEntry - stringsEntrySize);
+
+ /* Write the Double in the Strings section */
+ try {
+ buffer.putDouble(sv.unboxDouble());
+ } catch (StateValueTypeException e) {
+ /*
+ * This should not happen, since the value told us it was of
+ * type Double (corrupted value?)
+ */
+ e.printStackTrace();
+ }
+ if (buffer.position() != endPosOfStringEntry) {
+ throw new IllegalStateException();
+ }
+ buffer.reset();
+ break;
+
default:
break;
}
case LONG:
/* The value's bytes are written directly into the strings section */
return LONG_ENTRY_SIZE;
+ case DOUBLE:
+ /* The value is also written directly into the strings section */
+ return DOUBLE_ENTRY_SIZE;
case STRING:
try {
/* String's length + 2 (1 byte for size, 1 byte for \0 at the end */
return TYPE_STRING;
case LONG:
return TYPE_LONG;
+ case DOUBLE:
+ return TYPE_DOUBLE;
default:
/* Should not happen if the switch is fully covered */
throw new IllegalStateException();
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statevalue;
+
+/**
+ * A state value containing a double primitive.
+ *
+ * @author Alexandre Montplaisir
+ */
+final class DoubleStateValue extends TmfStateValue {
+
+ private final double valueDouble;
+
+ public DoubleStateValue(double value) {
+ valueDouble = value;
+ }
+
+ @Override
+ public Type getType() {
+ return Type.INTEGER;
+ }
+
+ @Override
+ public boolean isNull() {
+ return false;
+ }
+
+ @Override
+ public Double getValue() {
+ return valueDouble;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%3f", valueDouble); //$NON-NLS-1$
+ }
+
+ // ------------------------------------------------------------------------
+ // Unboxing methods
+ // ------------------------------------------------------------------------
+
+ @Override
+ public double unboxDouble() {
+ return valueDouble;
+ }
+}
INTEGER,
/** 64-bit integer value */
LONG,
+ /** IEEE 754 double precision number */
+ DOUBLE,
/** Variable-length string value */
STRING,
}
*/
long unboxLong() throws StateValueTypeException;
+ /**
+ * Read the contained value as a 'double' primitive
+ *
+ * @return The double contained in the state value
+ * @throws StateValueTypeException
+ * If the contained value cannot be read as a double
+ */
+ double unboxDouble() throws StateValueTypeException;
+
/**
* Read the contained value as a String
*
return -1;
}
+ @Override
+ public double unboxDouble() {
+ return Double.NaN;
+ }
+
@Override
public String unboxStr() {
return "nullValue"; //$NON-NLS-1$
return new LongStateValue(longValue);
}
+ /**
+ * Factory constructor for Double state values
+ *
+ * @param value
+ * The double value to contain
+ * @return The newly-created TmfStateValue object
+ */
+ public static TmfStateValue newValueDouble(double value) {
+ if (value == Double.NaN) {
+ return nullValue();
+ }
+ return new DoubleStateValue(value);
+ }
+
/**
* Factory constructor for String state values
*
throw new StateValueTypeException(unboxErrMsg("Long")); //$NON-NLS-1$
}
+ @Override
+ public double unboxDouble() throws StateValueTypeException {
+ throw new StateValueTypeException(unboxErrMsg("Double")); //$NON-NLS-1$
+ }
+
@Override
public String unboxStr() throws StateValueTypeException {
throw new StateValueTypeException(unboxErrMsg("String")); //$NON-NLS-1$
* @since 2.1*/
public static String TypeLong;
+ /** Label for type Double */
+ public static String TypeDouble;
+
/** Label for the type String
* @since 2.1*/
public static String TypeString;
value = String.valueOf(state.unboxLong());
item.setText(TYPE_COL, Messages.TypeLong);
break;
+ case DOUBLE:
+ value = String.valueOf(state.unboxDouble());
+ item.setText(TYPE_COL, Messages.TypeDouble);
+ break;
case STRING:
value = state.unboxStr();
item.setText(TYPE_COL, Messages.TypeString);
};
thread.start();
}
-
+
/**
* Update the display to use the updated timestamp format
*
FilterButton=Display Only Change
TypeInteger=Int
TypeLong=Long
+TypeDouble=Double
TypeString=String
\ No newline at end of file