public class CompositeDataSupport extends Object implements CompositeData, Serializable
CompositeData
interface.Constructor and Description |
---|
CompositeDataSupport(CompositeType type,
Map<String,?> items)
Constructs a new
CompositeDataSupport instance with the
specified type using field names and values from the supplied map. |
CompositeDataSupport(CompositeType type,
String[] names,
Object[] values)
Constructs a new
CompositeDataSupport instance with the
specified type using the supplied arrays of field names and
values. |
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(String key)
Returns true if this
CompositeData instance contains
the specified key. |
boolean |
containsValue(Object value)
Returns true if this
CompositeData instance has
a value equal to that supplied. |
boolean |
equals(Object obj)
Compares the specified object with this object for equality.
|
Object |
get(String key)
Retrieves the value for the specified key.
|
Object[] |
getAll(String[] keys)
Returns the appropriate value for each key in the given array,
using the same ordering.
|
CompositeType |
getCompositeType()
Returns the composite type which corresponds to this instance
of
CompositeData . |
int |
hashCode()
Returns the hash code of this instance.
|
String |
toString()
Returns a textual representation of this instance.
|
Collection<?> |
values()
Returns a read-only collection of the values associated with
this instance.
|
public CompositeDataSupport(CompositeType type, Map<String,?> items) throws OpenDataException
CompositeDataSupport
instance with the
specified type using field names and values from the supplied map.
The keys of the map become the field names, while the values
become the values of each respective field. This constructor simply
calls the other constructor, with the two arrays formed using the
keys and values of this map, respectively. Thus, the input parameters
given should conform to the same requirements given there (i.e. no
null values or empty strings).type
- the composite type of this composite data structure.items
- a mapping of field names to values. This should match
the mappings given by the type (i.e. for each mapping
in the type, there should be a corresponding field name
with a value of the correct type).IllegalArgumentException
- if the type, the map or any of the keys
or values in the map are null
,
or if any key from the map is an empty
string.OpenDataException
- if a mismatch occurs between the map and the
field name/type specification given by the
CompositeType
instance. This may be
due to the two having a different size, a
mismatch between keys or an incorrectly typed
value.ArrayStoreException
- if one of the keys is not a
String
(thus calling a failure
in converting the keys to an array of strings).public CompositeDataSupport(CompositeType type, String[] names, Object[] values) throws OpenDataException
CompositeDataSupport
instance with the
specified type using the supplied arrays of field names and
values. Neither the type, the two arrays or any elements of the
arrays may be null
. The String
s
within the names
array must be non-empty. The
arrays must match in size and order, as each element of the
names
array is matched against the corresponding
value in the values
array. Internally, the two are
stored in a map, lexographically ordered using the field names.
The data given should also conform to the description of the
instance given by the CompositeType
instance supplied.type
- the composite type of this composite data structure.names
- the field names.values
- the corresponding values of the fields.IllegalArgumentException
- if the type, the arrays or any of the keys
or values in the arrays are null
,
or if any key from names
is
an empty string. This also occurs if the
arrays differ in length.OpenDataException
- if a mismatch occurs between the arrays and the
field name/type specification given by the
CompositeType
instance. This may be
due to a differing number of field names, a
mismatch between names or an incorrectly typed
value.public boolean containsKey(String key)
CompositeData
instance contains
the specified key. This method always returns false for
an input key equal to null
or the empty string.containsKey
in interface CompositeData
key
- the key to find in the structure.public boolean containsValue(Object value)
CompositeData
instance has
a value equal to that supplied.containsValue
in interface CompositeData
value
- the value to look for.public boolean equals(Object obj)
CompositeData
with the same name-value
mappings and types. The two compared instances may be
equivalent even if they represent different implementations of
CompositeData
.equals
in interface CompositeData
equals
in class Object
obj
- the object to compare for equality.obj
is equal to this
.Object.hashCode()
public Object get(String key)
get
in interface CompositeData
key
- the key whose value should be returned.IllegalArgumentException
- if the key is null
or the empty string.InvalidKeyException
- if the key does not exist.public Object[] getAll(String[] keys)
getAll
in interface CompositeData
keys
- the keys whose values should be returned.IllegalArgumentException
- if one of the keys is
null
or the
empty string.InvalidKeyException
- if one of the keys does not exist.public CompositeType getCompositeType()
CompositeData
.getCompositeType
in interface CompositeData
public int hashCode()
e1.equals(e2)
implies
e1.hashCode() == e2.hashCode(), holds for any pair
of instances, e1
and e2
. However,
this relies on the other instance implementing the
hashCode
method correctly, if it is not an
instance of CompositeDataSupport
.
hashCode
in interface CompositeData
hashCode
in class Object
CompositeData
.Object.equals(Object)
public String toString()
key=value
for each pair of key and value.toString
in interface CompositeData
toString
in class Object
String
representation of the
object.Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public Collection<?> values()
values
in interface CompositeData