Revert "ss: Add serialization logic to state values"
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 14 Apr 2016 21:24:57 +0000 (17:24 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 14 Apr 2016 23:14:45 +0000 (19:14 -0400)
This reverts commit ce148788289534e20b56d0790a8ad93ce2e6473d.

Change-Id: I81e3a1f3557ef8edceaf930ba9b8d8cb3b23f200
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/70711
Reviewed-by: Hudson CI
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueTestBase.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/DoubleStateValue.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/ITmfStateValue.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/IntegerStateValue.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/LongStateValue.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/NullStateValue.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/StringStateValue.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/statevalue/TmfStateValue.java

index 16aa794841871131041abbafbd2b50427d85e120..841ecc8589a7ac7e9b51b83ce056155d6c0091e4 100644 (file)
@@ -85,18 +85,4 @@ public abstract class StateValueTestBase {
     public void testIsNull() {
         assertFalse(getStateValueFixture().isNull());
     }
-
-    /**
-     * Test state value serialization and deserialization, using
-     * {@link ITmfStateValue#serialize()} and
-     * {@link TmfStateValue#readSerializedValue}.
-     */
-    @Test
-    public void testSerialization() {
-        ITmfStateValue initialValue = getStateValueFixture();
-        byte[] serializedValue = initialValue.serialize();
-        ITmfStateValue readValue = TmfStateValue.readSerializedValue(serializedValue);
-
-        assertEquals(initialValue, readValue);
-    }
 }
index 71785014da254dcb28e08b9ac4cefda9397222bd..d53c83c5602495583be8bc9afa09db0752ce3579 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.tracecompass.statesystem.core.statevalue;
 
-import java.nio.ByteBuffer;
-
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 
@@ -60,14 +58,6 @@ final class DoubleStateValue extends TmfStateValue {
         return String.format("%3f", value); //$NON-NLS-1$
     }
 
-    @Override
-    public byte[] serialize() {
-        ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES + Double.BYTES);
-        buffer.put(getType().getByte());
-        buffer.putDouble(value);
-        return buffer.array();
-    }
-
     // ------------------------------------------------------------------------
     // Unboxing methods
     // ------------------------------------------------------------------------
index 490f51e683a09965cf0c7819877adeb4d14e6583..a5a9e864032b954b9f514e29025a61377b1aa48a 100644 (file)
@@ -24,61 +24,17 @@ public interface ITmfStateValue extends Comparable<ITmfStateValue> {
     /**
      * The supported types of state values
      */
-    enum Type {
-
+    public enum Type {
         /** Null value, for an interval not carrying any information */
-        NULL((byte) -1),
+        NULL,
         /** 32-bit integer value */
-        INTEGER((byte) 0),
+        INTEGER,
         /** 64-bit integer value */
-        LONG((byte) 1),
+        LONG,
         /** IEEE 754 double precision number */
-        DOUBLE((byte) 2),
+        DOUBLE,
         /** Variable-length string value */
-        STRING((byte) 3);
-
-        private final byte fTypeByte;
-
-        private Type(byte type) {
-            fTypeByte = type;
-        }
-
-        /**
-         * Get the corresponding Type from its byte representation.
-         *
-         * @param type
-         *            The type byte
-         * @return The corresponding Type enum element
-         * @throws IllegalArgumentException
-         *             If the type byte is not recognized
-         * @since 2.0
-         */
-        public static Type getTypeFromByte(byte type) {
-            switch (type) {
-            case -1:
-                return NULL;
-            case 0:
-                return INTEGER;
-            case 1:
-                return LONG;
-            case 2:
-                return DOUBLE;
-            case 3:
-                return STRING;
-            default:
-                throw new IllegalArgumentException();
-            }
-        }
-
-        /**
-         * Get the byte representation of this type.
-         *
-         * @return The type byte
-         * @since 2.0
-         */
-        public byte getByte() {
-            return fTypeByte;
-        }
+        STRING,
     }
 
     /**
@@ -134,18 +90,4 @@ public interface ITmfStateValue extends Comparable<ITmfStateValue> {
      */
     String unboxStr();
 
-    /**
-     * Serialize this state value into a byte array.
-     *
-     * The format of this array should always be:
-     *
-     * <pre>[type byte][payload]</pre>
-     *
-     * and the type will determine the layout of [payload].
-     *
-     * @return The serialized form of the state value
-     * @since 2.0
-     */
-    byte[] serialize();
-
 }
index 54eb5c80308f779570144122d3adf04611d9831e..41216f2153ca8395bf771dffd6664ccefe8ed575 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.tracecompass.statesystem.core.statevalue;
 
-import java.nio.ByteBuffer;
-
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 
@@ -60,14 +58,6 @@ final class IntegerStateValue extends TmfStateValue {
         return String.format("%3d", value); //$NON-NLS-1$
     }
 
-    @Override
-    public byte[] serialize() {
-        ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES + Integer.BYTES);
-        buffer.put(getType().getByte());
-        buffer.putInt(value);
-        return buffer.array();
-    }
-
     // ------------------------------------------------------------------------
     // Unboxing methods
     // ------------------------------------------------------------------------
@@ -108,4 +98,5 @@ final class IntegerStateValue extends TmfStateValue {
         }
 
     }
+
 }
index dae703845a8e4fb271b098cec5be9199e25ae2b5..0770024a133d99979f43d7b0a510abbe2171385f 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.tracecompass.statesystem.core.statevalue;
 
-import java.nio.ByteBuffer;
-
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 
@@ -60,14 +58,6 @@ final class LongStateValue extends TmfStateValue {
         return String.format("%3d", value); //$NON-NLS-1$
     }
 
-    @Override
-    public byte[] serialize() {
-        ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES + Long.BYTES);
-        buffer.put(getType().getByte());
-        buffer.putLong(value);
-        return buffer.array();
-    }
-
     // ------------------------------------------------------------------------
     // Unboxing methods
     // ------------------------------------------------------------------------
index d096bcb6c4faeb889f484b4ab5340687b5cf81a3..c71d71c0b65d09eafc986feefd4d45fd23b605c4 100644 (file)
@@ -25,8 +25,7 @@ import org.eclipse.jdt.annotation.Nullable;
  */
 final class NullStateValue extends TmfStateValue {
 
-    private static final byte[] EMPTY_ARRAY = new byte[0];
-    private static final String STR_VALUE = "nullValue"; //$NON-NLS-1$
+    private final String value = "nullValue"; //$NON-NLS-1$
 
     @Override
     public Type getType() {
@@ -50,12 +49,7 @@ final class NullStateValue extends TmfStateValue {
 
     @Override
     public String toString() {
-        return STR_VALUE;
-    }
-
-    @Override
-    public byte[] serialize() {
-        return EMPTY_ARRAY;
+        return value;
     }
 
     // ------------------------------------------------------------------------
@@ -79,7 +73,7 @@ final class NullStateValue extends TmfStateValue {
 
     @Override
     public String unboxStr() {
-        return STR_VALUE;
+        return value;
     }
 
     @Override
@@ -96,4 +90,5 @@ final class NullStateValue extends TmfStateValue {
          */
         return -(other.compareTo(this));
     }
+
 }
index 635bdea40562426c2d27dd2403aaf0894d34d46a..4e56b8f6efa7186b3e7335c07fb8ec7328af5a9a 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.tracecompass.statesystem.core.statevalue;
 
-import java.nio.ByteBuffer;
-
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 
@@ -60,15 +58,6 @@ final class StringStateValue extends TmfStateValue {
         return value;
     }
 
-    @Override
-    public byte[] serialize() {
-        byte[] strBytes = value.getBytes();
-        ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES + strBytes.length);
-        buffer.put(getType().getByte());
-        buffer.put(strBytes);
-        return buffer.array();
-    }
-
     // ------------------------------------------------------------------------
     // Unboxing methods
     // ------------------------------------------------------------------------
index e781238a12f18c5a4c6f5802102ddbdf6b92d9b7..c724410d21706952447b59424e33a6d8411b5bf1 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.tracecompass.statesystem.core.statevalue;
 
-import java.nio.ByteBuffer;
-
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.statesystem.core.Activator;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
@@ -63,55 +61,6 @@ public abstract class TmfStateValue implements ITmfStateValue {
         return nullValue;
     }
 
-    /**
-     * Read a serialized value (obtained with the {@link #serialize()} method)
-     * into a real {@link TmfStateValue} object.
-     *
-     * @param array
-     *            The serialized state value
-     * @return The state value object
-     * @since 2.0
-     */
-    public static TmfStateValue readSerializedValue(byte[] array) {
-        if (array.length == 0) {
-            /* This represents a null value */
-            return nullValue;
-        }
-
-        ByteBuffer buffer = ByteBuffer.wrap(array);
-
-        byte typeByte = buffer.get();
-        Type type = Type.getTypeFromByte(typeByte);
-        switch (type) {
-        case NULL: {
-            /* Should have been an empty array, but we'll accept it anyway */
-            return nullValue;
-        }
-        case INTEGER: {
-            int value = buffer.getInt();
-            return newValueInt(value);
-        }
-        case LONG: {
-            long value = buffer.getLong();
-            return newValueLong(value);
-        }
-        case DOUBLE: {
-            double value = buffer.getDouble();
-            return newValueDouble(value);
-        }
-        case STRING: {
-            /* The remaining of the buffer is the string's bytes */
-            int size = array.length - 1;
-            byte[] strBytes = new byte[size];
-            buffer.get(strBytes);
-            String value = new String(strBytes);
-            return newValueString(value);
-        }
-        default:
-            throw new IllegalArgumentException();
-        }
-    }
-
     /**
      * Factory constructor for Integer state values
      *
This page took 0.031942 seconds and 5 git commands to generate.