javax.management.openmbean

Class CompositeDataSupport

Implemented Interfaces:
CompositeData, Serializable

public class CompositeDataSupport
extends Object
implements CompositeData, Serializable

Provides an implementation of the CompositeData interface.
Since:
1.5
See Also:
Serialized Form

Constructor Summary

CompositeDataSupport(CompositeType type, Map 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.

Method Summary

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.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

CompositeDataSupport

public CompositeDataSupport(CompositeType type,
                            Map items)
            throws OpenDataException
Constructs a new 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).
Parameters:
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).
Throws:
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).

CompositeDataSupport

public CompositeDataSupport(CompositeType type,
                            String[] names,
                            Object[] values)
            throws OpenDataException
Constructs a new 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 Strings 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.
Parameters:
type - the composite type of this composite data structure.
names - the field names.
values - the corresponding values of the fields.
Throws:
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.

Method Details

containsKey

public boolean containsKey(String key)
Returns true if this CompositeData instance contains the specified key. This method always returns false for an input key equal to null or the empty string.
Specified by:
containsKey in interface CompositeData
Parameters:
key - the key to find in the structure.
Returns:
true if the key exists.

containsValue

public boolean containsValue(Object value)
Returns true if this CompositeData instance has a value equal to that supplied.
Specified by:
containsValue in interface CompositeData
Parameters:
value - the value to look for.
Returns:
true if the value exists.

equals

public boolean equals(Object obj)
Compares the specified object with this object for equality. The object is judged equivalent if it is non-null, and also an instance of CompositeData with the same name-value mappings and types. The two compared instances may be equivalent even if they represent different implementations of CompositeData.
Specified by:
equals in interface CompositeData
Overrides:
equals in interface Object
Parameters:
obj - the object to compare for equality.
Returns:
true if obj is equal to this.

get

public Object get(String key)
Retrieves the value for the specified key.
Specified by:
get in interface CompositeData
Parameters:
key - the key whose value should be returned.
Returns:
the matching value.
Throws:
IllegalArgumentException - if the key is null or the empty string.
InvalidKeyException - if the key does not exist.

getAll

public Object[] getAll(String[] keys)
Returns the appropriate value for each key in the given array, using the same ordering.
Specified by:
getAll in interface CompositeData
Parameters:
keys - the keys whose values should be returned.
Returns:
the matching values.
Throws:
IllegalArgumentException - if one of the keys is null or the empty string.
InvalidKeyException - if one of the keys does not exist.

getCompositeType

public CompositeType getCompositeType()
Returns the composite type which corresponds to this instance of CompositeData.
Specified by:
getCompositeType in interface CompositeData
Returns:
the composite type for this instance.

hashCode

public int hashCode()
Returns the hash code of this instance. The hash code is computed as the sum of the hash codes of all the values plus the hash code of the composite type. As equality comparisons take place using this same information, this should ensure that the property, 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.
Specified by:
hashCode in interface CompositeData
Overrides:
hashCode in interface Object
Returns:
the hash code of this CompositeData.

toString

public String toString()
Returns a textual representation of this instance. The exact format is left up to the implementation, but it should contain the name of the implementing class, the name of the type and a mapping of the form key=value for each pair of key and value.
Specified by:
toString in interface CompositeData
Overrides:
toString in interface Object
Returns:
a String representation of the object.

values

public Collection values()
Returns a read-only collection of the values associated with this instance. The values are sorted using the lexicographic ordering of the corresponding keys.
Specified by:
values in interface CompositeData
Returns:
the values of this instance.

CompositeData.java -- A composite data structure implementation. Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.