- java.lang.Object
-
- javax.management.openmbean.OpenType<T>
-
- javax.management.openmbean.ArrayType<T>
-
- All Implemented Interfaces:
Serializable
public class ArrayType<T> extends OpenType<T>
TheArrayTypeclass is the open type class whose instances describe all open data values which are n-dimensional arrays of open data values.Examples of valid
ArrayTypeinstances are:// 2-dimension array of java.lang.String ArrayType<String[][]> a1 = new ArrayType<String[][]>(2, SimpleType.STRING); // 1-dimension array of int ArrayType<int[]> a2 = new ArrayType<int[]>(SimpleType.INTEGER, true); // 1-dimension array of java.lang.Integer ArrayType<Integer[]> a3 = new ArrayType<Integer[]>(SimpleType.INTEGER, false); // 4-dimension array of int ArrayType<int[][][][]> a4 = new ArrayType<int[][][][]>(3, a2); // 4-dimension array of java.lang.Integer ArrayType<Integer[][][][]> a5 = new ArrayType<Integer[][][][]>(3, a3); // 1-dimension array of java.lang.String ArrayType<String[]> a6 = new ArrayType<String[]>(SimpleType.STRING, false); // 1-dimension array of long ArrayType<long[]> a7 = new ArrayType<long[]>(SimpleType.LONG, true); // 1-dimension array of java.lang.Integer ArrayType<Integer[]> a8 = ArrayType.getArrayType(SimpleType.INTEGER); // 2-dimension array of java.lang.Integer ArrayType<Integer[][]> a9 = ArrayType.getArrayType(a8); // 2-dimension array of int ArrayType<int[][]> a10 = ArrayType.getPrimitiveArrayType(int[][].class); // 3-dimension array of int ArrayType<int[][][]> a11 = ArrayType.getArrayType(a10); // 1-dimension array of float ArrayType<float[]> a12 = ArrayType.getPrimitiveArrayType(float[].class); // 2-dimension array of float ArrayType<float[][]> a13 = ArrayType.getArrayType(a12); // 1-dimension array of javax.management.ObjectName ArrayType<ObjectName[]> a14 = ArrayType.getArrayType(SimpleType.OBJECTNAME); // 2-dimension array of javax.management.ObjectName ArrayType<ObjectName[][]> a15 = ArrayType.getArrayType(a14); // 3-dimension array of java.lang.String ArrayType<String[][][]> a16 = new ArrayType<String[][][]>(3, SimpleType.STRING); // 1-dimension array of java.lang.String ArrayType<String[]> a17 = new ArrayType<String[]>(1, SimpleType.STRING); // 2-dimension array of java.lang.String ArrayType<String[][]> a18 = new ArrayType<String[][]>(1, a17); // 3-dimension array of java.lang.String ArrayType<String[][][]> a19 = new ArrayType<String[][][]>(1, a18);- Since:
- 1.5
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields declared in class javax.management.openmbean.OpenType
ALLOWED_CLASSNAMES, ALLOWED_CLASSNAMES_LIST
-
-
Constructor Summary
Constructors Constructor Description ArrayType(int dimension, OpenType<?> elementType)Constructs anArrayTypeinstance describing open data values which are arrays with dimension dimension of elements whose open type is elementType.ArrayType(SimpleType<?> elementType, boolean primitiveArray)Constructs a unidimensionalArrayTypeinstance for the suppliedSimpleType.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Compares the specifiedobjparameter with thisArrayTypeinstance for equality.static <E> ArrayType<E[]>getArrayType(OpenType<E> elementType)Create anArrayTypeinstance in a type-safe manner.intgetDimension()Returns the dimension of arrays described by thisArrayTypeinstance.OpenType<?>getElementOpenType()Returns the open type of element values contained in the arrays described by thisArrayTypeinstance.static <T> ArrayType<T>getPrimitiveArrayType(Class<T> arrayClass)Create anArrayTypeinstance in a type-safe manner.inthashCode()Returns the hash code value for thisArrayTypeinstance.booleanisPrimitiveArray()Returnstrueif the open data values this open type describes are primitive arrays,falseotherwise.booleanisValue(Object obj)Tests whether obj is a value for thisArrayTypeinstance.StringtoString()Returns a string representation of thisArrayTypeinstance.-
Methods declared in class javax.management.openmbean.OpenType
getClassName, getDescription, getTypeName, isArray
-
-
-
-
Constructor Detail
-
ArrayType
public ArrayType(int dimension, OpenType<?> elementType) throws OpenDataExceptionConstructs anArrayTypeinstance describing open data values which are arrays with dimension dimension of elements whose open type is elementType.When invoked on an
ArrayTypeinstance, thegetClassNamemethod returns the class name of the array instances it describes (following the rules defined by thegetNamemethod ofjava.lang.Class), not the class name of the array elements (which is returned by a call togetElementOpenType().getClassName()).The internal field corresponding to the type name of this
ArrayTypeinstance is also set to the class name of the array instances it describes. In other words, the methodsgetClassNameandgetTypeNamereturn the same string value. The internal field corresponding to the description of thisArrayTypeinstance is set to a string value which follows the following template:- if non-primitive array:
<dimension>-dimension array of <element_class_name> - if primitive array:
<dimension>-dimension array of <primitive_type_of_the_element_class_name>
As an example, the following piece of code:
would produce the following output:ArrayType<String[][][]> t = new ArrayType<String[][][]>(3, SimpleType.STRING); System.out.println("array class name = " + t.getClassName()); System.out.println("element class name = " + t.getElementOpenType().getClassName()); System.out.println("array type name = " + t.getTypeName()); System.out.println("array type description = " + t.getDescription());
And the following piece of code which is equivalent to the one listed above would also produce the same output:array class name = [[[Ljava.lang.String; element class name = java.lang.String array type name = [[[Ljava.lang.String; array type description = 3-dimension array of java.lang.StringArrayType<String[]> t1 = new ArrayType<String[]>(1, SimpleType.STRING); ArrayType<String[][]> t2 = new ArrayType<String[][]>(1, t1); ArrayType<String[][][]> t3 = new ArrayType<String[][][]>(1, t2); System.out.println("array class name = " + t3.getClassName()); System.out.println("element class name = " + t3.getElementOpenType().getClassName()); System.out.println("array type name = " + t3.getTypeName()); System.out.println("array type description = " + t3.getDescription());- Parameters:
dimension- the dimension of arrays described by thisArrayTypeinstance; must be greater than or equal to 1.elementType- the open type of element values contained in the arrays described by thisArrayTypeinstance; must be an instance of eitherSimpleType,CompositeType,TabularTypeor anotherArrayTypewith aSimpleType,CompositeTypeorTabularTypeas itselementType.- Throws:
IllegalArgumentException- ifdimensionis not a positive integer.OpenDataException- if elementType's className is not one of the allowed Java class names for open data.
- if non-primitive array:
-
ArrayType
public ArrayType(SimpleType<?> elementType, boolean primitiveArray) throws OpenDataException
Constructs a unidimensionalArrayTypeinstance for the suppliedSimpleType.This constructor supports the creation of arrays of primitive types when
primitiveArrayistrue.For primitive arrays the
getElementOpenType()method returns theSimpleTypecorresponding to the wrapper type of the primitive type of the array.When invoked on an
ArrayTypeinstance, thegetClassNamemethod returns the class name of the array instances it describes (following the rules defined by thegetNamemethod ofjava.lang.Class), not the class name of the array elements (which is returned by a call togetElementOpenType().getClassName()).The internal field corresponding to the type name of this
ArrayTypeinstance is also set to the class name of the array instances it describes. In other words, the methodsgetClassNameandgetTypeNamereturn the same string value. The internal field corresponding to the description of thisArrayTypeinstance is set to a string value which follows the following template:- if non-primitive array:
1-dimension array of <element_class_name> - if primitive array:
1-dimension array of <primitive_type_of_the_element_class_name>
As an example, the following piece of code:
would produce the following output:ArrayType<int[]> t = new ArrayType<int[]>(SimpleType.INTEGER, true); System.out.println("array class name = " + t.getClassName()); System.out.println("element class name = " + t.getElementOpenType().getClassName()); System.out.println("array type name = " + t.getTypeName()); System.out.println("array type description = " + t.getDescription());array class name = [I element class name = java.lang.Integer array type name = [I array type description = 1-dimension array of int- Parameters:
elementType- theSimpleTypeof the element values contained in the arrays described by thisArrayTypeinstance.primitiveArray-truewhen this array describes primitive arrays.- Throws:
IllegalArgumentException- ifdimensionis not a positive integer.OpenDataException- ifprimitiveArrayistrueandelementTypeis not a validSimpleTypefor a primitive type.- Since:
- 1.6
- if non-primitive array:
-
-
Method Detail
-
getDimension
public int getDimension()
Returns the dimension of arrays described by thisArrayTypeinstance.- Returns:
- the dimension.
-
getElementOpenType
public OpenType<?> getElementOpenType()
Returns the open type of element values contained in the arrays described by thisArrayTypeinstance.- Returns:
- the element type.
-
isPrimitiveArray
public boolean isPrimitiveArray()
Returnstrueif the open data values this open type describes are primitive arrays,falseotherwise.- Returns:
- true if this is a primitive array type.
- Since:
- 1.6
-
isValue
public boolean isValue(Object obj)
Tests whether obj is a value for thisArrayTypeinstance.This method returns
trueif and only if obj is not null, obj is an array and any one of the following istrue:- if this
ArrayTypeinstance describes an array ofSimpleTypeelements or their corresponding primitive types, obj's class name is the same as the className field defined for thisArrayTypeinstance (i.e. the class name returned by thegetClassNamemethod, which includes the dimension information),
- if this
ArrayTypeinstance describes an array of classes implementing theTabularDatainterface or theCompositeDatainterface, obj is assignable to such a declared array, and each element contained in {obj is either null or a valid value for the element's open type specified by thisArrayTypeinstance.
- if this
-
equals
public boolean equals(Object obj)
Compares the specifiedobjparameter with thisArrayTypeinstance for equality.Two
ArrayTypeinstances are equal if and only if they describe array instances which have the same dimension, elements' open type and primitive array flag.- Specified by:
equalsin classOpenType<T>- Parameters:
obj- the object to be compared for equality with thisArrayTypeinstance; if obj isnullor is not an instance of the classArrayTypethis method returnsfalse.- Returns:
trueif the specified object is equal to thisArrayTypeinstance.- See Also:
Object.hashCode()
-
hashCode
public int hashCode()
Returns the hash code value for thisArrayTypeinstance.The hash code of an
ArrayTypeinstance is the sum of the hash codes of all the elements of information used inequalscomparisons (i.e. dimension, elements' open type and primitive array flag). The hashcode for a primitive value is the hashcode of the corresponding boxed object (e.g. the hashcode fortrueisBoolean.TRUE.hashCode()). This ensures thatt1.equals(t2)implies thatt1.hashCode()==t2.hashCode()for any twoArrayTypeinstancest1andt2, as required by the general contract of the methodObject.hashCode().As
ArrayTypeinstances are immutable, the hash code for this instance is calculated once, on the first call tohashCode, and then the same value is returned for subsequent calls.- Overrides:
hashCodein classObject- Returns:
- the hash code value for this
ArrayTypeinstance - See Also:
Object.equals(java.lang.Object)
-
toString
public String toString()
Returns a string representation of thisArrayTypeinstance.The string representation consists of the name of this class (i.e.
javax.management.openmbean.ArrayType), the type name, the dimension, the elements' open type and the primitive array flag defined for this instance.As
ArrayTypeinstances are immutable, the string representation for this instance is calculated once, on the first call totoString, and then the same value is returned for subsequent calls.
-
getArrayType
public static <E> ArrayType<E[]> getArrayType(OpenType<E> elementType) throws OpenDataException
Create anArrayTypeinstance in a type-safe manner.Multidimensional arrays can be built up by calling this method as many times as necessary.
Calling this method twice with the same parameters may return the same object or two equal but not identical objects.
As an example, the following piece of code:
would produce the following output:ArrayType<String[]> t1 = ArrayType.getArrayType(SimpleType.STRING); ArrayType<String[][]> t2 = ArrayType.getArrayType(t1); ArrayType<String[][][]> t3 = ArrayType.getArrayType(t2); System.out.println("array class name = " + t3.getClassName()); System.out.println("element class name = " + t3.getElementOpenType().getClassName()); System.out.println("array type name = " + t3.getTypeName()); System.out.println("array type description = " + t3.getDescription());array class name = [[[Ljava.lang.String; element class name = java.lang.String array type name = [[[Ljava.lang.String; array type description = 3-dimension array of java.lang.String- Type Parameters:
E- the Java type that described instances must have- Parameters:
elementType- the open type of element values contained in the arrays described by thisArrayTypeinstance; must be an instance of eitherSimpleType,CompositeType,TabularTypeor anotherArrayTypewith aSimpleType,CompositeTypeorTabularTypeas itselementType.- Returns:
- an
ArrayTypeinstance - Throws:
OpenDataException- if elementType's className is not one of the allowed Java class names for open data.- Since:
- 1.6
-
getPrimitiveArrayType
public static <T> ArrayType<T> getPrimitiveArrayType(Class<T> arrayClass)
Create anArrayTypeinstance in a type-safe manner.Calling this method twice with the same parameters may return the same object or two equal but not identical objects.
As an example, the following piece of code:
would produce the following output:ArrayType<int[][][]> t = ArrayType.getPrimitiveArrayType(int[][][].class); System.out.println("array class name = " + t.getClassName()); System.out.println("element class name = " + t.getElementOpenType().getClassName()); System.out.println("array type name = " + t.getTypeName()); System.out.println("array type description = " + t.getDescription());array class name = [[[I element class name = java.lang.Integer array type name = [[[I array type description = 3-dimension array of int- Type Parameters:
T- the Java type that described instances must have- Parameters:
arrayClass- a primitive array class such asint[].class,boolean[][].class, etc. ThegetElementOpenType()method of the returnedArrayTypereturns theSimpleTypecorresponding to the wrapper type of the primitive type of the array.- Returns:
- an
ArrayTypeinstance - Throws:
IllegalArgumentException- if arrayClass is not a primitive array.- Since:
- 1.6
-
-