Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEventField.java
index 5cac0bd9f244e1ac7415895e48c52312d911e974..6729b776ece9f06e0dc7170fa74f32e426ee494f 100644 (file)
@@ -7,7 +7,7 @@
  * http://www.eclipse.org/legal/epl-v10.html
  * 
  * Contributors:
- *   Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
+ *   Francois Chouinard - Initial API and implementation
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.event;
@@ -16,29 +16,70 @@ package org.eclipse.linuxtools.tmf.event;
  * <b><u>TmfEventField</u></b>
  * <p>
  * A basic event field.
+ * 
+ * TODO: Add support for field hierarchy.
  */
-public class TmfEventField {
+public class TmfEventField implements Cloneable {
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Attributes
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
-    private final Object fValue;
+       protected TmfEventContent fParent;
+       protected String fFieldId;
+       protected Object fValue;
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Constructors
-    // ========================================================================
+    // ------------------------------------------------------------------------
+
+    @SuppressWarnings("unused")
+       private TmfEventField() {
+               throw new AssertionError();
+    }
 
     /**
+     * @param parent
+     * @param id
      * @param value
      */
-    public TmfEventField(Object value) {
-        fValue = value;
+    public TmfEventField(TmfEventContent parent, String id, Object value) {
+       if (id == null) {
+               throw new IllegalArgumentException();
+       }
+       fParent  = parent;
+       fFieldId = id;
+        fValue   = value;
+    }
+
+    /**
+     * @param other
+     */
+    public TmfEventField(TmfEventField other) {
+       if (other == null)
+               throw new IllegalArgumentException();
+       fParent  = other.fParent;
+       fFieldId = other.fFieldId;
+               fValue   = other.fValue;
     }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Accessors
-    // ========================================================================
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return
+     */
+    public TmfEventContent getParent() {
+        return fParent;
+    }
+
+    /**
+     * @return
+     */
+    public String getId() {
+        return fFieldId;
+    }
 
     /**
      * @return
@@ -47,14 +88,51 @@ public class TmfEventField {
         return fValue;
     }
 
-    // ========================================================================
-    // Operators
-    // ========================================================================
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#toString()
+    /**
+     * @param value new field value
      */
-    public String toString() {
-        return fValue.toString();
+    protected void setValue(Object value) {
+        fValue = value;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+               int result = 17;
+               result = 37 * result + fFieldId.hashCode();
+               result = 37 * result + fValue.hashCode();
+        return result;
     }
-}
+
+       @Override
+       public boolean equals(Object other) {
+       if (!(other instanceof TmfEventField))
+               return false;
+               TmfEventField o = (TmfEventField) other;
+               return fParent.equals(o.fParent) && fFieldId.equals(o.fFieldId) && fValue.equals(o.fValue); 
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+       public String toString() {
+        return "[TmfEventField(" + fFieldId + ":" + fValue.toString() + ")]";
+    }
+    @Override
+       public TmfEventField clone() {
+       TmfEventField clone = null;
+       try {
+                       clone = (TmfEventField) super.clone();
+                       clone.fParent = fParent;
+                       clone.fFieldId = new String(fFieldId);
+                       clone.fValue = null;                    
+               } catch (CloneNotSupportedException e) {
+                       e.printStackTrace();
+               }
+               return clone;
+    }
+
+
+}
\ No newline at end of file
This page took 0.025177 seconds and 5 git commands to generate.