* Contributors:
* Francois Chouinard - Initial API and implementation
* Francois Chouinard - Updated as per TMF Event Model 1.0
+ * Alexandre Montplaisir - Removed Cloneable, made immutable
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.event;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
* @see ITmfEvent
* @see ITmfEventType
*/
-public class TmfEventField implements ITmfEventField, Cloneable {
+public class TmfEventField implements ITmfEventField {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private String fName;
- private Object fValue;
- private ITmfEventField[] fFields;
+ private final String fName;
+ private final Object fValue;
+ private final ITmfEventField[] fFields;
- private String[] fFieldNames;
- private Map<String, ITmfEventField> fNameMapping;
+ private final String[] fFieldNames;
+ private final Map<String, ITmfEventField> fNameMapping;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- /**
- * Default constructor
- */
- @SuppressWarnings("unused")
- private TmfEventField() {
- }
-
/**
* Constructor for a structural field
*
}
fName = name;
fValue = value;
- fFields = (fields != null) ? Arrays.copyOf(fields, fields.length) : null;
- populateStructs();
+ fFields = fields;
+
+ /* Fill the fFieldNames and fNameMapping structures */
+ final int nbFields = (fFields != null) ? fFields.length : 0;
+ fFieldNames = new String[nbFields];
+ fNameMapping = new HashMap<String, ITmfEventField>();
+
+ for (int i = 0; i < nbFields; i++) {
+ final String curName = fFields[i].getName();
+ fFieldNames[i] = curName;
+ fNameMapping.put(curName, fFields[i]);
+ }
}
/**
fValue = field.fValue;
fFields = field.fFields;
fFieldNames = field.fFieldNames;
- populateStructs();
+ fNameMapping = field.fNameMapping;
}
// ------------------------------------------------------------------------
*/
@Override
public String[] getFieldNames() {
- return Arrays.copyOf(fFieldNames, fFieldNames.length);
+ return fFieldNames;
}
/* (non-Javadoc)
*/
@Override
public ITmfEventField[] getFields() {
- return (fFields != null) ? Arrays.copyOf(fFields, fFields.length) : new ITmfEventField[0];
+ return (fFields != null) ? fFields : new ITmfEventField[0];
}
/* (non-Javadoc)
return null;
}
- // ------------------------------------------------------------------------
- // Convenience setters
- // ------------------------------------------------------------------------
-
- /**
- * @param value new field raw value
- * @param fields the corresponding fields
- */
- protected void setValue(final Object value, final ITmfEventField[] fields) {
- fValue = value;
- fFields = (fields != null) ? Arrays.copyOf(fields, fields.length) : null;
- populateStructs();
- }
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return new TmfEventField(ITmfEventField.ROOT_FIELD_ID, fields);
}
- /*
- * Populate the subfield names and the name map
- */
- private void populateStructs() {
- final int nbFields = (fFields != null) ? fFields.length : 0;
- fFieldNames = new String[nbFields];
- fNameMapping = new HashMap<String, ITmfEventField>();
- for (int i = 0; i < nbFields; i++) {
- final String name = fFields[i].getName();
- fFieldNames[i] = name;
- fNameMapping.put(name, fFields[i]);
- }
- }
-
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- public TmfEventField clone() {
- TmfEventField clone = null;
- try {
- clone = (TmfEventField) super.clone();
- clone.fName = fName;
- clone.fValue = fValue;
- clone.fFields = (fFields != null) ? fFields.clone() : null;
- clone.populateStructs();
- } catch (final CloneNotSupportedException e) {
- }
- return clone;
- }
-
// ------------------------------------------------------------------------
// Object
// ------------------------------------------------------------------------