javax.management.openmbean
public class ArrayType<T> extends OpenType<T>
Since: 1.5
Constructor Summary | |
---|---|
ArrayType(int dim, OpenType<?> elementType) Constructs a new ArrayType instance for an array of the specified type with the supplied number of dimensions. | |
ArrayType(SimpleType<?> elementType, boolean primitiveArray) Constructs a new ArrayType instance for a unidimensional array of the specified SimpleType. |
Method Summary | |
---|---|
boolean | equals(Object obj) Compares this array type with another object for equality. |
static <E> ArrayType<E[]> | getArrayType(OpenType<E> elementType) |
int | getDimension()
Returns the number of dimensions used by arrays
of this type.
|
OpenType<?> | getElementOpenType()
Returns the open type descriptor which describes
the type of the elements of this array type.
|
static <T> ArrayType<T> | getPrimitiveArrayType(Class<T> type) |
int | hashCode() Returns the hash code of the array type. |
boolean | isPrimitiveArray()
Returns true if this instance represents an array of
a primitive type.
|
boolean | isValue(Object obj) Returns true if the specified object is a member of this array type. |
String | toString() Returns a textual representation of this instance. |
Constructs a new ArrayType instance for an array of the
specified type with the supplied number of dimensions. The attributes
used by the superclass, OpenType, are automatically defined,
based on these values. Both the class name and type name are set
to the value returned by the getName of
the array's class (i.e. the element type, preceded by n instances of
'[' and an 'L', where n is the number of dimensions the array has).
The description is based upon the template n-dimension array
of e
, where n is the number of dimensions of the array, and
e is the element type. The class name of the actual elements is
obtainable by calling getClassName on the result
of getElementOpenType.
As an example, the array type returned by
new ArrayType(6, SimpleType.INTEGER)
has the following
values:
Attribute | Value |
Class Name | [[[[[[Ljava.lang.Integer;
|
Type Name | [[[[[[Ljava.lang.Integer;
|
Description | 6-dimension array of
java.lang.Integer |
Element Type Class Name | java.lang.Integer
|
The dimensions of the array must be equal to or greater than 1. The element type must be an instance of SimpleType, CompositeType or TabularType.
Parameters: dim the dimensions of the array. elementType the type of the elements of the array.
Throws: IllegalArgumentException if dim
is less than 1. OpenDataException if the element type is not an instance of either
SimpleType, CompositeType
or TabularType.
Constructs a new ArrayType instance for a unidimensional array of the specified SimpleType. The attributes used by the superclass, OpenType, are automatically defined, based on these values. Both the class name and type name are set to the value returned by the getName of the array's class. If the array is of a primitive type (indicated by giving {@code primitiveArray} the value {@code true}), the name will be '[' followed by the appropriate letter for the primitive type (see getName). If the array is not of a primitive type, then the name is formed from the element type, preceded by '[' and an 'L', in the same way as when the multi-dimensional constructor is used.
The description is based upon the template 1-dimension array
of e
, where e is either the primitive type or a class name,
depending on whether the array itself is of a primitive type or not.
The class name of the actual elements is obtainable by calling
getClassName on the result of
getElementOpenType. This will be the appropriate wrapper
class for a primitive type.
As an example, the array type returned by
new ArrayType(SimpleType.INTEGER, true)
has the following
values:
Attribute | Value |
Class Name | [I
|
Type Name | [I
|
Description | 1-dimension array of int |
Element Type Class Name | java.lang.Integer
|
Parameters: elementType the type of the elements of the array. primitiveArray true if the array should be of a primitive type.
Throws: OpenDataException if {@code primitiveArray} is {@code true}, and elementType is not a valid SimpleType for a primitive type.
Since: 1.6
Compares this array type with another object for equality. The objects are judged to be equal if:
obj
is not null.obj
is an instance of
ArrayType.Parameters: obj the object to compare with.
Returns: true if the conditions above hold.
Returns a new ArrayType instance in a type-safe manner, by ensuring that the type of the given OpenType matches the component type used in the type of the returned instance. If the given OpenType is a SimpleType, CompositeType or TabularType, then a 1-dimensional array of that type is returned. Otherwise, if the type is an ArrayType of n dimensions, the returned type is also an ArrayType but of n+1 dimensions. For example, {@code ArrayType.getArrayType(ArrayType.getArrayType(SimpleType.STRING))} returns a 2-dimensional array of SimpleType.
This method caches its results, so that the same instance is returned from subsequent calls with the same parameters.
Parameters: elementType the element type of the new array type.
Throws: OpenDataException if the class name of {@code elementType} is not in ALLOWED_CLASSNAMES_LIST.
Since: 1.6
Returns: the number of dimensions.
Returns: the type of the elements.
Returns a new ArrayType instance for the given primitive type in a type-safe* manner, by ensuring that the type of the given OpenType matches the type used in the returned instance. If the type is an array of n dimensions, the returned type is also an ArrayType of n dimensions.
As an example, the array type returned by
getPrimitiveArrayType(Integer.TYPE)
has the
following values:
Attribute | Value |
Class Name | [I
|
Type Name | [I
|
Description | 1-dimension array of int |
Element Type Class Name | java.lang.Integer
|
This method caches its results, so that the same instance is returned from subsequent calls with the same parameters.
Parameters: type the type of the new ArrayType.
Throws: IllegalArgumentException if the type is not a primitive array.
Since: 1.6
Returns the hash code of the array type. This is computed as the sum of the hash code of the element type together with the number of dimensions the array has and the primitive array flag. These are the same elements of the type that are compared as part of the equals method, thus ensuring that the hashcode is compatible with the equality test.
As instances of this class are immutable, the hash code is computed just once for each instance and reused throughout its life.
Returns: the hash code of this instance.
Returns: true if the array is of a primitive type.
Returns true if the specified object is a member of this array type. The object is judged to be so if it is non-null, an array and one of the following two conditions holds:
Parameters: obj the object to test for membership.
Returns: true if the object is a member of this type.
Returns a textual representation of this instance. This
is constructed using the class name
(javax.management.openmbean.ArrayType
)
and each element of the instance which is relevant to
the definition of equals(java.lang.Object)
and
hashCode()
(i.e. the type name, the number of
dimensions and the element type).
As instances of this class are immutable, the return value is computed just once for each instance and reused throughout its life.
Returns: a @link{java.lang.String} instance representing the instance in textual form.