cern.cmw
Class Data

java.lang.Object
  extended by cern.cmw.Data
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SLEquipData

public class Data
extends Object
implements Serializable

Allows clients and servers to exchange values whose types are not fixed at compile time.

A Data object may contain zero or more DataEntry objects; each entry is uniquely identified by a string tag. The entries can be accessed sequentially or randomly by tags.

You can create DataEntry objects independently and then insert them into a Data object, or use value insertion/extraction methods provided by the Data class for all supported data types (see DataEntry for the description of supported data types). For a given type X, these methods are:

void insert(String tag, X x)
This method inserts a scalar value of type X into the entry identified by tag. If there is no such entry, it will be created and added to the data object.
void insert(X x)
Same as above for the default tag.
void insert(String tag, X[] x)
This method inserts an array value of type X into the entry identified by tag. If there is no such entry, it will be created and added to the data object.
void insert(X[] x)
Same as above for the default tag.
X extractX(String tag)
This method allows the extraction of a scalar value of type X from the entry identified by tag. Throws BadParameter if there is no such entry in the data object, and TypeMismatch if the type of the value contained in the DataEntry is not X.
X extractX()
Same as above for the default tag.
X[] extractX(String tag)
This method allows the extraction of an array value of type X from the entry identified by tag. Throws BadParameter if there is no such entry in the data object, and TypeMismatch if the entry contains something other than an array of type X, or nothing.
X[] extractX()
Same as above for the default tag.

This example creates an empty Data object, inserts three entries into it, and prints out contents of the data:


     Data data = new Data();
     data.insert("a",(int) 123);
     data.insert("b","xyz");
     data.insert((double) 1.23);
     System.out.println(data);
  

To retrieve the values, use the following code:


     try
     {
        int a = data.extractInt("a");
        String b = data.extractString("b");
        double def = data.extractDouble();
        // ...
     }
     catch(CmwException ex)
     {
        System.out.println("Exception: "+ ex);
     }
  
The Data class is not thread-safe: multiple threads cannot share a single Data object without the need for external synchronization.

See Also:
DataEntry, Serialized Form

Constructor Summary
Data()
          Constructs an empty Data object.
 
Method Summary
 void add(String tag, DataEntry entry)
          Adds a DataEntry with the specified tag to contents of this Data object.
 boolean contains(String tag)
          Returns true if this Data object contains an entry with the specified tag.
 Data copy()
          Creates and returns a deep copy of this Data object.
 boolean extractBoolean()
          Returns the boolean stored in the default data entry.
 boolean extractBoolean(String tag)
          Returns the boolean stored in the specified data entry.
 boolean[] extractBooleanArray()
          Returns the boolean array stored in the default data entry.
 boolean[] extractBooleanArray(String tag)
          Returns the boolean array stored in the specified data entry.
 byte extractByte()
          Returns the byte stored in the default data entry.
 byte extractByte(String tag)
          Returns the byte stored in the specified data entry.
 byte[] extractByteArray()
          Returns the byte array stored in the default data entry.
 byte[] extractByteArray(String tag)
          Returns the byte array stored in the specified data entry.
 double extractDouble()
          Returns the double stored in the default data entry.
 double extractDouble(String tag)
          Returns the double stored in the specified data entry.
 double[] extractDoubleArray()
          Returns the double array stored in the default data entry.
 double[] extractDoubleArray(String tag)
          Returns the double array stored in the specified data entry.
 float extractFloat()
          Returns the float stored in the default data entry.
 float extractFloat(String tag)
          Returns the float stored in the specified data entry.
 float[] extractFloatArray()
          Returns the float array stored in the default data entry.
 float[] extractFloatArray(String tag)
          Returns the float array stored in the specified data entry.
 int extractInt()
          Returns the int stored in the default data entry.
 int extractInt(String tag)
          Returns the int stored in the specified data entry.
 int[] extractIntArray()
          Returns the int array stored in the default data entry.
 int[] extractIntArray(String tag)
          Returns the int array stored in the specified data entry.
 long extractLong()
          Returns the long stored in the default data entry.
 long extractLong(String tag)
          Returns the long stored in the specified data entry.
 long[] extractLongArray()
          Returns the long array stored in the default data entry.
 long[] extractLongArray(String tag)
          Returns the long array stored in the specified data entry.
 Object extractObject()
          Returns the Object stored in the Default data entry.
 Object extractObject(String tag)
          Returns the Object stored in the specified data entry.
 short extractShort()
          Returns the short stored in the default data entry.
 short extractShort(String tag)
          Returns the short stored in the specified data entry.
 short[] extractShortArray()
          Returns the short array stored in the default data entry.
 short[] extractShortArray(String tag)
          Returns the short array stored in the specified data entry.
 String extractString()
          Returns the String stored in the default data entry.
 String extractString(String tag)
          Returns the String stored in the specified data entry.
 String[] extractStringArray()
          Returns the String array stored in the default data entry.
 String[] extractStringArray(String tag)
          Returns the String array stored in the specified data entry.
 DataEntry get(String tag)
          Returns an entry with the specified tag or null if there is no such entry in this Data.
 String[] getTags()
          Returns an unordered String array that contains tags of all contained entries.
 void insert(boolean value)
          Inserts a boolean value into the default data entry.
 void insert(boolean[] value)
          Inserts a boolean array value into the default data entry.
 void insert(byte value)
          Inserts a byte value into the default data entry.
 void insert(byte[] value)
          Inserts a byte array value into the default data entry.
 void insert(double value)
          Inserts a double value into the default data entry.
 void insert(double[] value)
          Inserts a double array value into the default data entry.
 void insert(float value)
          Inserts a float value into the default data entry.
 void insert(float[] value)
          Inserts a float array value into the default data entry.
 void insert(int value)
          Inserts a int value into the default data entry.
 void insert(int[] value)
          Inserts an int array value into the default data entry.
 void insert(long value)
          Inserts a long value into the default data entry.
 void insert(long[] value)
          Inserts a long array value into the default data entry.
 void insert(short value)
          Inserts a short value into the default data entry.
 void insert(short[] value)
          Inserts a short array value into the default data entry.
 void insert(String value)
          Inserts a String value into the default data entry.
 void insert(String[] value)
          Inserts a String array value into the default data entry.
 void insert(String tag, boolean value)
          Inserts a boolean value into the specified entry.
 void insert(String tag, boolean[] value)
          Inserts a boolean array value into the specified data entry.
 void insert(String tag, byte value)
          Inserts a byte value into the specified entry.
 void insert(String tag, byte[] value)
          Inserts a byte array value into the specified data entry.
 void insert(String tag, double value)
          Inserts a double value into the specified entry.
 void insert(String tag, double[] value)
          Inserts a double array value into the specified data entry.
 void insert(String tag, float value)
          Inserts a float value into the specified entry.
 void insert(String tag, float[] value)
          Inserts a float array value into the specified data entry.
 void insert(String tag, int value)
          Inserts a int value into the specified entry.
 void insert(String tag, int[] value)
          Inserts an int array value into the specified data entry.
 void insert(String tag, long value)
          Inserts a long value into the specified entry.
 void insert(String tag, long[] value)
          Inserts a long array value into the specified data entry.
 void insert(String tag, short value)
          Inserts a short value into the specified entry.
 void insert(String tag, short[] value)
          Inserts a short array value into the specified data entry.
 void insert(String tag, String value)
          Inserts a String value into the specified entry.
 void insert(String tag, String[] value)
          Inserts a String array value into the specified data entry.
 void insertObject(Object value)
          Inserts a Object value into the default entry.
 void insertObject(String tag, Object value)
          Inserts a Object value into the specified entry.
 boolean isEmpty()
          Returns true if this Data contains no entries; false otherwise.
 void remove(String tag)
          Removes an entry with the given tag from this Data object.
 void removeAll()
          Removes all entries from this Data.
 int size()
          Returns the number of entries in this Data.
 String toString()
          Returns a string representation of this Data object.
 String toString(int maxElements)
          Returns a string representation of this Data object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Data

public Data()
Constructs an empty Data object.

Method Detail

isEmpty

public boolean isEmpty()
Returns true if this Data contains no entries; false otherwise.


size

public int size()
Returns the number of entries in this Data.


getTags

public String[] getTags()
Returns an unordered String array that contains tags of all contained entries. Returns a zero length array if this Data object is empty.


add

public void add(String tag,
                DataEntry entry)
Adds a DataEntry with the specified tag to contents of this Data object.


contains

public boolean contains(String tag)
Returns true if this Data object contains an entry with the specified tag.


get

public DataEntry get(String tag)
Returns an entry with the specified tag or null if there is no such entry in this Data.


remove

public void remove(String tag)
Removes an entry with the given tag from this Data object. This method does nothing if there is no such entry in the Data.


removeAll

public void removeAll()
Removes all entries from this Data.


copy

public Data copy()
Creates and returns a deep copy of this Data object.


insert

public void insert(boolean value)
Inserts a boolean value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   boolean value)
Inserts a boolean value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(boolean[] value)
Inserts a boolean array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   boolean[] value)
Inserts a boolean array value into the specified data entry. If the entry does not exist, it will be created.


extractBoolean

public boolean extractBoolean()
                       throws BadParameter,
                              TypeMismatch
Returns the boolean stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a \c boolean, or nothing.

extractBoolean

public boolean extractBoolean(String tag)
                       throws BadParameter,
                              TypeMismatch
Returns the boolean stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a boolean, or nothing.

extractBooleanArray

public boolean[] extractBooleanArray()
                              throws BadParameter,
                                     TypeMismatch
Returns the boolean array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a boolean array, or nothing.

extractBooleanArray

public boolean[] extractBooleanArray(String tag)
                              throws BadParameter,
                                     TypeMismatch
Returns the boolean array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a boolean array, or nothing.

insert

public void insert(byte value)
Inserts a byte value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   byte value)
Inserts a byte value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(byte[] value)
Inserts a byte array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   byte[] value)
Inserts a byte array value into the specified data entry. If the entry does not exist, it will be created.


extractByte

public byte extractByte()
                 throws BadParameter,
                        TypeMismatch
Returns the byte stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a byte, or nothing.

extractByte

public byte extractByte(String tag)
                 throws BadParameter,
                        TypeMismatch
Returns the byte stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a byte, or nothing.

extractByteArray

public byte[] extractByteArray()
                        throws BadParameter,
                               TypeMismatch
Returns the byte array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a byte array, or nothing.

extractByteArray

public byte[] extractByteArray(String tag)
                        throws BadParameter,
                               TypeMismatch
Returns the byte array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a byte array, or nothing.

insert

public void insert(short value)
Inserts a short value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   short value)
Inserts a short value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(short[] value)
Inserts a short array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   short[] value)
Inserts a short array value into the specified data entry. If the entry does not exist, it will be created.


extractShort

public short extractShort()
                   throws BadParameter,
                          TypeMismatch
Returns the short stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a short, or nothing.

extractShort

public short extractShort(String tag)
                   throws BadParameter,
                          TypeMismatch
Returns the short stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a short, or nothing.

extractShortArray

public short[] extractShortArray()
                          throws BadParameter,
                                 TypeMismatch
Returns the short array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a short array, or nothing.

extractShortArray

public short[] extractShortArray(String tag)
                          throws BadParameter,
                                 TypeMismatch
Returns the short array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a short array, or nothing.

insert

public void insert(int value)
Inserts a int value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   int value)
Inserts a int value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(int[] value)
Inserts an int array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   int[] value)
Inserts an int array value into the specified data entry. If the entry does not exist, it will be created.


extractInt

public int extractInt()
               throws BadParameter,
                      TypeMismatch
Returns the int stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than an int, or nothing.

extractInt

public int extractInt(String tag)
               throws BadParameter,
                      TypeMismatch
Returns the int stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than an int, or nothing.

extractIntArray

public int[] extractIntArray()
                      throws BadParameter,
                             TypeMismatch
Returns the int array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than an int array, or nothing.

extractIntArray

public int[] extractIntArray(String tag)
                      throws BadParameter,
                             TypeMismatch
Returns the int array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than an int array, or nothing.

insert

public void insert(long value)
Inserts a long value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   long value)
Inserts a long value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(long[] value)
Inserts a long array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   long[] value)
Inserts a long array value into the specified data entry. If the entry does not exist, it will be created.


extractLong

public long extractLong()
                 throws BadParameter,
                        TypeMismatch
Returns the long stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a long, or nothing.

extractLong

public long extractLong(String tag)
                 throws BadParameter,
                        TypeMismatch
Returns the long stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a long, or nothing.

extractLongArray

public long[] extractLongArray()
                        throws BadParameter,
                               TypeMismatch
Returns the long array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a long array, or nothing.

extractLongArray

public long[] extractLongArray(String tag)
                        throws BadParameter,
                               TypeMismatch
Returns the long array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a long array, or nothing.

insert

public void insert(float value)
Inserts a float value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   float value)
Inserts a float value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(float[] value)
Inserts a float array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   float[] value)
Inserts a float array value into the specified data entry. If the entry does not exist, it will be created.


extractFloat

public float extractFloat()
                   throws BadParameter,
                          TypeMismatch
Returns the float stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a float, or nothing.

extractFloat

public float extractFloat(String tag)
                   throws BadParameter,
                          TypeMismatch
Returns the float stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a float, or nothing.

extractFloatArray

public float[] extractFloatArray()
                          throws BadParameter,
                                 TypeMismatch
Returns the float array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a float array, or nothing.

extractFloatArray

public float[] extractFloatArray(String tag)
                          throws BadParameter,
                                 TypeMismatch
Returns the float array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a float array, or nothing.

insert

public void insert(double value)
Inserts a double value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   double value)
Inserts a double value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(double[] value)
Inserts a double array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   double[] value)
Inserts a double array value into the specified data entry. If the entry does not exist, it will be created.


extractDouble

public double extractDouble()
                     throws BadParameter,
                            TypeMismatch
Returns the double stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a double, or nothing.

extractDouble

public double extractDouble(String tag)
                     throws BadParameter,
                            TypeMismatch
Returns the double stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a double, or nothing.

extractDoubleArray

public double[] extractDoubleArray()
                            throws BadParameter,
                                   TypeMismatch
Returns the double array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a double array, or nothing.

extractDoubleArray

public double[] extractDoubleArray(String tag)
                            throws BadParameter,
                                   TypeMismatch
Returns the double array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a double array, or nothing.

insert

public void insert(String value)
Inserts a String value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   String value)
Inserts a String value into the specified entry. If the entry does not exist, it will be created.


insert

public void insert(String[] value)
Inserts a String array value into the default data entry. If the entry does not exist, it will be created.


insert

public void insert(String tag,
                   String[] value)
Inserts a String array value into the specified data entry. If the entry does not exist, it will be created.


extractString

public String extractString()
                     throws BadParameter,
                            TypeMismatch
Returns the String stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a String, or nothing.

extractString

public String extractString(String tag)
                     throws BadParameter,
                            TypeMismatch
Returns the String stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a String, or nothing.

extractStringArray

public String[] extractStringArray()
                            throws BadParameter,
                                   TypeMismatch
Returns the String array stored in the default data entry.

Throws:
BadParameter - thrown if this Data does not contain the default entry
TypeMismatch - thrown if the entry contains something other than a String array, or nothing.

extractStringArray

public String[] extractStringArray(String tag)
                            throws BadParameter,
                                   TypeMismatch
Returns the String array stored in the specified data entry.

Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a String array, or nothing.

toString

public String toString()
Returns a string representation of this Data object. This call is equivalent to toString(100).

Overrides:
toString in class Object
See Also:
toString(int)

toString

public String toString(int maxElements)
Returns a string representation of this Data object. Not more then the specified number of elements will be included in the string for each contained array value.


insertObject

public void insertObject(String tag,
                         Object value)
Inserts a Object value into the specified entry. If the entry does not exist, it will be created.

Parameters:
tag - the tag of the value to be inserted
value - the Object to insert

insertObject

public void insertObject(Object value)
Inserts a Object value into the default entry. If the entry does not exist, it will be created.

Parameters:
value - the Object to insert

extractObject

public Object extractObject(String tag)
                     throws BadParameter,
                            TypeMismatch
Returns the Object stored in the specified data entry.

Parameters:
tag - the tag of the value to be extracted
Throws:
BadParameter - thrown if this Data does not contain the specified entry
TypeMismatch - thrown if the entry contains something other than a Object, or nothing.

extractObject

public Object extractObject()
                     throws TypeMismatch,
                            BadParameter
Returns the Object stored in the Default data entry.

Throws:
BadParameter - thrown if this Data does not contain a default specified entry
TypeMismatch - thrown if the entry contains something other than a Object, or nothing.


Copyright © 2007 CERN. All Rights Reserved.