|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcern.cmw.Data
public class Data
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:
default
tag.
default
tag.
default
tag.
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.
DataEntry
,
Serialized FormConstructor 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 |
---|
public Data()
Method Detail |
---|
public boolean isEmpty()
true
if this Data contains no entries;
false
otherwise.
public int size()
public String[] getTags()
public void add(String tag, DataEntry entry)
public boolean contains(String tag)
true
if this Data object contains an entry with the
specified tag.
public DataEntry get(String tag)
null
if there is
no such entry in this Data.
public void remove(String tag)
public void removeAll()
public Data copy()
public void insert(boolean value)
boolean
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, boolean value)
boolean
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(boolean[] value)
boolean
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, boolean[] value)
boolean
array value into the specified data entry.
If the entry does not exist, it will be created.
public boolean extractBoolean() throws BadParameter, TypeMismatch
boolean
stored in the default data entry.
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.public boolean extractBoolean(String tag) throws BadParameter, TypeMismatch
boolean
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a boolean
,
or nothing.public boolean[] extractBooleanArray() throws BadParameter, TypeMismatch
boolean
array stored in the default data entry.
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.public boolean[] extractBooleanArray(String tag) throws BadParameter, TypeMismatch
boolean
array stored in the specified data entry.
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.public void insert(byte value)
byte
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, byte value)
byte
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(byte[] value)
byte
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, byte[] value)
byte
array value into the specified data entry.
If the entry does not exist, it will be created.
public byte extractByte() throws BadParameter, TypeMismatch
byte
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than a byte
,
or nothing.public byte extractByte(String tag) throws BadParameter, TypeMismatch
byte
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a byte
,
or nothing.public byte[] extractByteArray() throws BadParameter, TypeMismatch
byte
array stored in the default data entry.
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.public byte[] extractByteArray(String tag) throws BadParameter, TypeMismatch
byte
array stored in the specified data entry.
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.public void insert(short value)
short
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, short value)
short
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(short[] value)
short
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, short[] value)
short
array value into the specified data entry.
If the entry does not exist, it will be created.
public short extractShort() throws BadParameter, TypeMismatch
short
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than a short
,
or nothing.public short extractShort(String tag) throws BadParameter, TypeMismatch
short
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a short
,
or nothing.public short[] extractShortArray() throws BadParameter, TypeMismatch
short
array stored in the default data entry.
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.public short[] extractShortArray(String tag) throws BadParameter, TypeMismatch
short
array stored in the specified data entry.
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.public void insert(int value)
int
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, int value)
int
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(int[] value)
int
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, int[] value)
int
array value into the specified data entry.
If the entry does not exist, it will be created.
public int extractInt() throws BadParameter, TypeMismatch
int
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than an int
,
or nothing.public int extractInt(String tag) throws BadParameter, TypeMismatch
int
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than an int
,
or nothing.public int[] extractIntArray() throws BadParameter, TypeMismatch
int
array stored in the default data entry.
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.public int[] extractIntArray(String tag) throws BadParameter, TypeMismatch
int
array stored in the specified data entry.
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.public void insert(long value)
long
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, long value)
long
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(long[] value)
long
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, long[] value)
long
array value into the specified data entry.
If the entry does not exist, it will be created.
public long extractLong() throws BadParameter, TypeMismatch
long
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than a long
,
or nothing.public long extractLong(String tag) throws BadParameter, TypeMismatch
long
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a long
,
or nothing.public long[] extractLongArray() throws BadParameter, TypeMismatch
long
array stored in the default data entry.
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.public long[] extractLongArray(String tag) throws BadParameter, TypeMismatch
long
array stored in the specified data entry.
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.public void insert(float value)
float
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, float value)
float
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(float[] value)
float
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, float[] value)
float
array value into the specified data entry.
If the entry does not exist, it will be created.
public float extractFloat() throws BadParameter, TypeMismatch
float
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than a float
,
or nothing.public float extractFloat(String tag) throws BadParameter, TypeMismatch
float
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a float
,
or nothing.public float[] extractFloatArray() throws BadParameter, TypeMismatch
float
array stored in the default data entry.
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.public float[] extractFloatArray(String tag) throws BadParameter, TypeMismatch
float
array stored in the specified data entry.
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.public void insert(double value)
double
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, double value)
double
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(double[] value)
double
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, double[] value)
double
array value into the specified data entry.
If the entry does not exist, it will be created.
public double extractDouble() throws BadParameter, TypeMismatch
double
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than a double
,
or nothing.public double extractDouble(String tag) throws BadParameter, TypeMismatch
double
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a double
,
or nothing.public double[] extractDoubleArray() throws BadParameter, TypeMismatch
double
array stored in the default data entry.
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.public double[] extractDoubleArray(String tag) throws BadParameter, TypeMismatch
double
array stored in the specified data entry.
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.public void insert(String value)
String
value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, String value)
String
value into the specified entry.
If the entry does not exist, it will be created.
public void insert(String[] value)
String
array value into the default data entry.
If the entry does not exist, it will be created.
public void insert(String tag, String[] value)
String
array value into the specified data entry.
If the entry does not exist, it will be created.
public String extractString() throws BadParameter, TypeMismatch
String
stored in the default data entry.
BadParameter
- thrown if this Data does not contain the default entry
TypeMismatch
- thrown if the entry contains something other than a String
,
or nothing.public String extractString(String tag) throws BadParameter, TypeMismatch
String
stored in the specified data entry.
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a String
,
or nothing.public String[] extractStringArray() throws BadParameter, TypeMismatch
String
array stored in the default data entry.
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.public String[] extractStringArray(String tag) throws BadParameter, TypeMismatch
String
array stored in the specified data entry.
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.public String toString()
toString(100)
.
toString
in class Object
toString(int)
public String toString(int maxElements)
public void insertObject(String tag, Object value)
Object
value into the specified entry.
If the entry does not exist, it will be created.
tag
- the tag of the value to be insertedvalue
- the Object to insertpublic void insertObject(Object value)
Object
value into the default entry.
If the entry does not exist, it will be created.
value
- the Object to insertpublic Object extractObject(String tag) throws BadParameter, TypeMismatch
Object
stored in the specified data entry.
tag
- the tag of the value to be extracted
BadParameter
- thrown if this Data does not contain the specified entry
TypeMismatch
- thrown if the entry contains something other than a Object
,
or nothing.public Object extractObject() throws TypeMismatch, BadParameter
Object
stored in the Default data entry.
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |