TMF: Add Variant field class to CtfTmfEventField
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 28 Mar 2013 15:59:01 +0000 (11:59 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 18 Apr 2013 20:20:13 +0000 (16:20 -0400)
A variant field class was necessary to not lose the name of the variant
field.  The output of a variant field type is now identical to that of
babeltrace.

Modified some comments and added the getFormattedValue to CTFStructField
to correctly handle empty structs.

Removed overriden toString functions that are not overridden anymore.

Change-Id: Iccffc6a2375df54945ff41614628760afcdf147f
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/11550
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java

index aff0160355434ed9287dfb8735096f87018e7684..b874071ea0279987425dfde2d58ad126d6c6dcc3 100644 (file)
@@ -192,6 +192,6 @@ public class CtfTmfEventFieldTest {
     public void testParseField_variant() {
         Definition fieldDef = fixture.lookupDefinition(VARIANT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
-        assertEquals("float=9.551467814359616E-38", result.toString());
+        assertEquals("test=float=9.551467814359616E-38", result.toString());
     }
 }
index 3485d5f8f4348d55b87d335f33fca36045752c29..6ac34e30d886b2362ab809d96a62e16eccb48e1d 100644 (file)
@@ -162,7 +162,8 @@ public abstract class CtfTmfEventField extends TmfEventField {
             String curFieldName = varDef.getCurrentFieldName();
             Definition curFieldDef = varDef.getDefinitions().get(curFieldName);
             if (curFieldDef != null) {
-                field = CtfTmfEventField.parseField(curFieldDef, curFieldName);
+                CtfTmfEventField subField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
+                field = new CTFVariantField(fieldName, subField);
             } else {
                 /* A safe-guard, but curFieldDef should never be null */
                 field = new CTFStringField(curFieldName, ""); //$NON-NLS-1$
@@ -177,7 +178,7 @@ public abstract class CtfTmfEventField extends TmfEventField {
 
     @Override
     public String toString() {
-        return getName() + '=' + getValue().toString();
+        return getName() + '=' + getFormattedValue();
     }
 
     /**
@@ -249,13 +250,6 @@ final class CTFIntegerField extends CtfTmfEventField {
         return formatNumber(getValue(), base);
     }
 
-    /**
-     * Custom-format the integer values depending on their base.
-     */
-    @Override
-    public String toString() {
-        return getName() + '=' + formatNumber(getValue(), base);
-    }
 }
 
 /**
@@ -324,13 +318,6 @@ final class CTFIntegerArrayField extends CtfTmfEventField {
         return formattedValue;
     }
 
-    /**
-     * Custom-format the integer values depending on their base.
-     */
-    @Override
-    public String toString() {
-        return getName() + '=' + getFormattedValue();
-    }
 }
 
 /**
@@ -385,17 +372,17 @@ final class CTFEnumField extends CtfTmfEventField {
 }
 
 /**
- * The CTF field implementation for struct fields with sub-types
+ * The CTF field implementation for struct fields with sub-fields
  *
  * @author gbastien
  */
 final class CTFStructField extends CtfTmfEventField {
 
     /**
-     * Constructor for CTFStringField.
+     * Constructor for CTFStructField.
      *
-     * @param strValue
-     *            The string value of this field
+     * @param fields
+     *            The children of this field
      * @param name
      *            The name of this field
      */
@@ -409,9 +396,36 @@ final class CTFStructField extends CtfTmfEventField {
     }
 
     @Override
-    public String toString() {
-        return getName() + '=' + Arrays.toString(getValue());
+    public String getFormattedValue() {
+        return Arrays.toString(getValue());
     }
+
+}
+
+/**
+ * The CTF field implementation for variant fields its child
+ *
+ * @author gbastien
+ */
+final class CTFVariantField extends CtfTmfEventField {
+
+    /**
+     * Constructor for CTFVariantField.
+     *
+     * @param field
+     *            The field selected for this variant
+     * @param name
+     *            The name of this field
+     */
+    CTFVariantField(String name, CtfTmfEventField field) {
+        super(name, field, new CtfTmfEventField[]{ field });
+    }
+
+    @Override
+    public CtfTmfEventField getValue() {
+        return (CtfTmfEventField) super.getValue();
+    }
+
 }
 
 /* Implement other possible fields types here... */
This page took 0.029445 seconds and 5 git commands to generate.