jdk/src/java.management/share/classes/javax/management/openmbean/ArrayType.java
author avstepan
Thu, 06 Aug 2015 13:59:10 +0300
changeset 32034 05676cfd40b5
parent 29927 9cc3e111a1d8
permissions -rw-r--r--
8133040: docs: replace <tt> tags (obsolete in html5) for java.management Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 28059
diff changeset
     2
 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.openmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ObjectStreamException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
    32
 * The {@code ArrayType} class is the <i>open type</i> class whose instances describe
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * all <i>open data</i> values which are n-dimensional arrays of <i>open data</i> values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Examples of valid {@code ArrayType} instances are:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    36
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * // 2-dimension array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * ArrayType<String[][]> a1 = new ArrayType<String[][]>(2, SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * // 1-dimension array of int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * ArrayType<int[]> a2 = new ArrayType<int[]>(SimpleType.INTEGER, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * // 1-dimension array of java.lang.Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * ArrayType<Integer[]> a3 = new ArrayType<Integer[]>(SimpleType.INTEGER, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * // 4-dimension array of int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * ArrayType<int[][][][]> a4 = new ArrayType<int[][][][]>(3, a2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * // 4-dimension array of java.lang.Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * ArrayType<Integer[][][][]> a5 = new ArrayType<Integer[][][][]>(3, a3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * // 1-dimension array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * ArrayType<String[]> a6 = new ArrayType<String[]>(SimpleType.STRING, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * // 1-dimension array of long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * ArrayType<long[]> a7 = new ArrayType<long[]>(SimpleType.LONG, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * // 1-dimension array of java.lang.Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * ArrayType<Integer[]> a8 = ArrayType.getArrayType(SimpleType.INTEGER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * // 2-dimension array of java.lang.Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * ArrayType<Integer[][]> a9 = ArrayType.getArrayType(a8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * // 2-dimension array of int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * ArrayType<int[][]> a10 = ArrayType.getPrimitiveArrayType(int[][].class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * // 3-dimension array of int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * ArrayType<int[][][]> a11 = ArrayType.getArrayType(a10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * // 1-dimension array of float
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * ArrayType<float[]> a12 = ArrayType.getPrimitiveArrayType(float[].class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * // 2-dimension array of float
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * ArrayType<float[][]> a13 = ArrayType.getArrayType(a12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * // 1-dimension array of javax.management.ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * ArrayType<ObjectName[]> a14 = ArrayType.getArrayType(SimpleType.OBJECTNAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * // 2-dimension array of javax.management.ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * ArrayType<ObjectName[][]> a15 = ArrayType.getArrayType(a14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * // 3-dimension array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * ArrayType<String[][][]> a16 = new ArrayType<String[][][]>(3, SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * // 1-dimension array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * ArrayType<String[]> a17 = new ArrayType<String[]>(1, SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * // 2-dimension array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * ArrayType<String[][]> a18 = new ArrayType<String[][]>(1, a17);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * // 3-dimension array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * ArrayType<String[][][]> a19 = new ArrayType<String[][][]>(1, a18);
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    93
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  Generification note: we could have defined a type parameter that is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  element type, with class ArrayType<E> extends OpenType<E[]>.  However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  that doesn't buy us all that much.  We can't say
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public OpenType<E> getElementOpenType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  because this ArrayType could be a multi-dimensional array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  For example, if we had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    ArrayType(2, SimpleType.INTEGER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  then E would have to be Integer[], while getElementOpenType() would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  return SimpleType.INTEGER, which is an OpenType<Integer>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  Furthermore, we would like to support int[] (as well as Integer[]) as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  an Open Type (RFE 5045358).  We would want this to be an OpenType<int[]>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  which can't be expressed as <E[]> because E can't be a primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  like int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
public class ArrayType<T> extends OpenType<T> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    static final long serialVersionUID = 720504429830309770L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @serial The dimension of arrays described by this {@link ArrayType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *         instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private int dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @serial The <i>open type</i> of element values contained in the arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *         described by this {@link ArrayType} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private OpenType<?> elementType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @serial This flag indicates whether this {@link ArrayType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *         describes a primitive array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private boolean primitiveArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private transient Integer  myHashCode = null;       // As this instance is immutable, these two values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private transient String   myToString = null;       // need only be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // indexes refering to columns in the PRIMITIVE_ARRAY_TYPES table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static final int PRIMITIVE_WRAPPER_NAME_INDEX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static final int PRIMITIVE_TYPE_NAME_INDEX = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static final int PRIMITIVE_TYPE_KEY_INDEX  = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static final int PRIMITIVE_OPEN_TYPE_INDEX  = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static final Object[][] PRIMITIVE_ARRAY_TYPES = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        { Boolean.class.getName(),   boolean.class.getName(), "Z", SimpleType.BOOLEAN },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        { Character.class.getName(), char.class.getName(),    "C", SimpleType.CHARACTER },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        { Byte.class.getName(),      byte.class.getName(),    "B", SimpleType.BYTE },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        { Short.class.getName(),     short.class.getName(),   "S", SimpleType.SHORT },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        { Integer.class.getName(),   int.class.getName(),     "I", SimpleType.INTEGER },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        { Long.class.getName(),      long.class.getName(),    "J", SimpleType.LONG },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        { Float.class.getName(),     float.class.getName(),   "F", SimpleType.FLOAT },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        { Double.class.getName(),    double.class.getName(),  "D", SimpleType.DOUBLE }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static boolean isPrimitiveContentType(final String primitiveKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (typeDescr[PRIMITIVE_TYPE_KEY_INDEX].equals(primitiveKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Return the key used to identify the element type in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * arrays - e.g. "Z" for boolean, "C" for char etc...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param elementClassName the wrapper class name of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *        element ("Boolean",  "Character", etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @return the key corresponding to the given type ("Z", "C", etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *         return null if the given elementClassName is not a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *         wrapper class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    static String getPrimitiveTypeKey(String elementClassName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (elementClassName.equals(typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                return (String)typeDescr[PRIMITIVE_TYPE_KEY_INDEX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Return the primitive type name corresponding to the given wrapper class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * e.g. "boolean" for "Boolean", "char" for "Character" etc...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param elementClassName the type of the array element ("Boolean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *        "Character", etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @return the primitive type name corresponding to the given wrapper class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *         ("boolean", "char", etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         return null if the given elementClassName is not a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *         wrapper type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    static String getPrimitiveTypeName(String elementClassName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (elementClassName.equals(typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                return (String)typeDescr[PRIMITIVE_TYPE_NAME_INDEX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Return the primitive open type corresponding to the given primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * e.g. SimpleType.BOOLEAN for "boolean", SimpleType.CHARACTER for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * "char", etc...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param primitiveTypeName the primitive type of the array element ("boolean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *        "char", etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @return the OpenType corresponding to the given primitive type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *         (SimpleType.BOOLEAN, SimpleType.CHARACTER, etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *         return null if the given elementClassName is not a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *         type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    static SimpleType<?> getPrimitiveOpenType(String primitiveTypeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (primitiveTypeName.equals(typeDescr[PRIMITIVE_TYPE_NAME_INDEX]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                return (SimpleType<?>)typeDescr[PRIMITIVE_OPEN_TYPE_INDEX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /* *** Constructor *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   225
     * Constructs an {@code ArrayType} instance describing <i>open data</i> values which are
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   226
     * arrays with dimension <var>dimension</var> of elements
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   227
     * whose <i>open type</i> is <var>elementType</var>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   229
     * When invoked on an {@code ArrayType} instance,
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   230
     * the {@link OpenType#getClassName() getClassName} method
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   231
     * returns the class name of the array instances it describes
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   232
     * (following the rules defined by the
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   233
     * {@link Class#getName() getName} method of {@code java.lang.Class}),
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   234
     * not the class name of the array elements
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   235
     * (which is returned by a call to {@code getElementOpenType().getClassName()}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   237
     * The internal field corresponding to the type name of this
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   238
     * {@code ArrayType} instance is also set to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * the class name of the array instances it describes.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   240
     * In other words, the methods {@code getClassName} and
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   241
     * {@code getTypeName} return the same string value.
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   242
     * The internal field corresponding to the description of this
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   243
     * {@code ArrayType} instance is set to a string value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * which follows the following template:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <ul>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   246
     * <li>if non-primitive array: <code><i>&lt;dimension&gt;</i>-dimension array
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   247
     *     of <i>&lt;element_class_name&gt;</i></code></li>
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   248
     * <li>if primitive array: <code><i>&lt;dimension&gt;</i>-dimension array
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   249
     *     of <i>&lt;primitive_type_of_the_element_class_name&gt;</i></code></li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * As an example, the following piece of code:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   253
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * ArrayType<String[][][]> t = new ArrayType<String[][][]>(3, SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * System.out.println("array class name       = " + t.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * System.out.println("element class name     = " + t.getElementOpenType().getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * System.out.println("array type name        = " + t.getTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * System.out.println("array type description = " + t.getDescription());
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   259
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * would produce the following output:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   261
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * array class name       = [[[Ljava.lang.String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * element class name     = java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * array type name        = [[[Ljava.lang.String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * array type description = 3-dimension array of java.lang.String
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   266
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * And the following piece of code which is equivalent to the one listed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * above would also produce the same output:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   269
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * ArrayType<String[]> t1 = new ArrayType<String[]>(1, SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * ArrayType<String[][]> t2 = new ArrayType<String[][]>(1, t1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * ArrayType<String[][][]> t3 = new ArrayType<String[][][]>(1, t2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * System.out.println("array class name       = " + t3.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * System.out.println("element class name     = " + t3.getElementOpenType().getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * System.out.println("array type name        = " + t3.getTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * System.out.println("array type description = " + t3.getDescription());
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   277
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   279
     * @param  dimension  the dimension of arrays described by this {@code ArrayType} instance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *                    must be greater than or equal to 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param  elementType  the <i>open type</i> of element values contained
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   283
     *                      in the arrays described by this {@code ArrayType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *                      instance; must be an instance of either
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   285
     *                      {@code SimpleType}, {@code CompositeType},
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   286
     *                      {@code TabularType} or another {@code ArrayType}
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   287
     *                      with a {@code SimpleType}, {@code CompositeType}
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   288
     *                      or {@code TabularType} as its {@code elementType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @throws IllegalArgumentException if {@code dimension} is not a positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *                                  integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @throws OpenDataException  if <var>elementType's className</var> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *                            one of the allowed Java class names for open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *                            data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public ArrayType(int dimension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                     OpenType<?> elementType) throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // Check and construct state defined by parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // We can't use the package-private OpenType constructor because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // we don't know if the elementType parameter is sane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        super(buildArrayClassName(dimension, elementType),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
              buildArrayClassName(dimension, elementType),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
              buildArrayDescription(dimension, elementType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // Check and construct state specific to ArrayType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (elementType.isArray()) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   308
            ArrayType<?> at = (ArrayType<?>) elementType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            this.dimension = at.getDimension() + dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            this.elementType = at.getElementOpenType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            this.primitiveArray = at.isPrimitiveArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            this.dimension = dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            this.elementType = elementType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            this.primitiveArray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Constructs a unidimensional {@code ArrayType} instance for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * supplied {@code SimpleType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * This constructor supports the creation of arrays of primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * types when {@code primitiveArray} is {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * For primitive arrays the {@link #getElementOpenType()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * returns the {@link SimpleType} corresponding to the wrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * type of the primitive type of the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   330
     * When invoked on an {@code ArrayType} instance,
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   331
     * the {@link OpenType#getClassName() getClassName} method
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   332
     * returns the class name of the array instances it describes
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   333
     * (following the rules defined by the
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   334
     * {@link Class#getName() getName} method of {@code java.lang.Class}),
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   335
     * not the class name of the array elements
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   336
     * (which is returned by a call to {@code getElementOpenType().getClassName()}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   338
     * The internal field corresponding to the type name of this
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   339
     * {@code ArrayType} instance is also set to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * the class name of the array instances it describes.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   341
     * In other words, the methods {@code getClassName} and
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   342
     * {@code getTypeName} return the same string value.
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   343
     * The internal field corresponding to the description
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   344
     * of this {@code ArrayType} instance is set to a string value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * which follows the following template:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <ul>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   347
     * <li>if non-primitive array: <code>1-dimension array
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   348
     *     of <i>&lt;element_class_name&gt;</i></code></li>
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   349
     * <li>if primitive array: <code>1-dimension array
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   350
     *     of <i>&lt;primitive_type_of_the_element_class_name&gt;</i></code></li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * As an example, the following piece of code:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   354
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * ArrayType<int[]> t = new ArrayType<int[]>(SimpleType.INTEGER, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * System.out.println("array class name       = " + t.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * System.out.println("element class name     = " + t.getElementOpenType().getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * System.out.println("array type name        = " + t.getTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * System.out.println("array type description = " + t.getDescription());
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   360
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * would produce the following output:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   362
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * array class name       = [I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * element class name     = java.lang.Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * array type name        = [I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * array type description = 1-dimension array of int
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   367
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param elementType the {@code SimpleType} of the element values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *                    contained in the arrays described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *                    {@code ArrayType} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param primitiveArray {@code true} when this array describes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *                       primitive arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @throws IllegalArgumentException if {@code dimension} is not a positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @throws OpenDataException if {@code primitiveArray} is {@code true} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * {@code elementType} is not a valid {@code SimpleType} for a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public ArrayType(SimpleType<?> elementType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                     boolean primitiveArray) throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // Check and construct state defined by parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // We can call the package-private OpenType constructor because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // set of SimpleTypes is fixed and SimpleType can't be subclassed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        super(buildArrayClassName(1, elementType, primitiveArray),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
              buildArrayClassName(1, elementType, primitiveArray),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
              buildArrayDescription(1, elementType, primitiveArray),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
              true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // Check and construct state specific to ArrayType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        this.dimension = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        this.elementType = elementType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        this.primitiveArray = primitiveArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /* Package-private constructor for callers we trust to get it right. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    ArrayType(String className, String typeName, String description,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   404
              int dimension, OpenType<?> elementType,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
              boolean primitiveArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        super(className, typeName, description, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        this.dimension = dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        this.elementType = elementType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        this.primitiveArray = primitiveArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private static String buildArrayClassName(int dimension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                              OpenType<?> elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        boolean isPrimitiveArray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (elementType.isArray()) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   417
            isPrimitiveArray = ((ArrayType<?>) elementType).isPrimitiveArray();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return buildArrayClassName(dimension, elementType, isPrimitiveArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private static String buildArrayClassName(int dimension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                              OpenType<?> elementType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                              boolean isPrimitiveArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (dimension < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                "Value of argument dimension must be greater than 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        StringBuilder result = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        String elementClassName = elementType.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        // Add N (= dimension) additional '[' characters to the existing array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        for (int i = 1; i <= dimension; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            result.append('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (elementType.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            result.append(elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            if (isPrimitiveArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                final String key = getPrimitiveTypeKey(elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                // Ideally we should throw an IllegalArgumentException here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                // but for compatibility reasons we throw an OpenDataException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                // (used to be thrown by OpenType() constructor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (key == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    throw new OpenDataException("Element type is not primitive: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                            + elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                result.append(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                result.append("L");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                result.append(elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                result.append(';');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private static String buildArrayDescription(int dimension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                                OpenType<?> elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        boolean isPrimitiveArray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (elementType.isArray()) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   463
            isPrimitiveArray = ((ArrayType<?>) elementType).isPrimitiveArray();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        return buildArrayDescription(dimension, elementType, isPrimitiveArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    private static String buildArrayDescription(int dimension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                OpenType<?> elementType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                boolean isPrimitiveArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (elementType.isArray()) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   473
            ArrayType<?> at = (ArrayType<?>) elementType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            dimension += at.getDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            elementType = at.getElementOpenType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            isPrimitiveArray = at.isPrimitiveArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
27957
24b4e6082f19 8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents: 25859
diff changeset
   478
        StringBuilder result = new StringBuilder();
24b4e6082f19 8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents: 25859
diff changeset
   479
        result.append(dimension).append("-dimension array of ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        final String elementClassName = elementType.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (isPrimitiveArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            // Convert from wrapper type to primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            final String primitiveType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    getPrimitiveTypeName(elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            // Ideally we should throw an IllegalArgumentException here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            // but for compatibility reasons we throw an OpenDataException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            // (used to be thrown by OpenType() constructor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (primitiveType == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                throw new OpenDataException("Element is not a primitive type: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            result.append(primitiveType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            result.append(elementClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /* *** ArrayType specific information methods *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   503
     * Returns the dimension of arrays described by this {@code ArrayType} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @return the dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public int getDimension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   513
     * Returns the <i>open type</i> of element values contained
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   514
     * in the arrays described by this {@code ArrayType} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @return the element type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    public OpenType<?> getElementOpenType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return elementType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   524
     * Returns {@code true} if the open data values this open
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   525
     * type describes are primitive arrays, {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @return true if this is a primitive array type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public boolean isPrimitiveArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return primitiveArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   537
     * Tests whether <var>obj</var> is a value for this {@code ArrayType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   540
     * This method returns {@code true} if and only if <var>obj</var>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * is not null, <var>obj</var> is an array and any one of the following
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   542
     * is {@code true}:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <ul>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   545
     * <li>if this {@code ArrayType} instance describes an array of
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   546
     * {@code SimpleType} elements or their corresponding primitive types,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <var>obj</var>'s class name is the same as the className field defined
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   548
     * for this {@code ArrayType} instance (i.e. the class name returned
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * by the {@link OpenType#getClassName() getClassName} method, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * includes the dimension information),<br>&nbsp;</li>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   551
     * <li>if this {@code ArrayType} instance describes an array of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * classes implementing the {@code TabularData} interface or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * {@code CompositeData} interface, <var>obj</var> is assignable to
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   554
     * such a declared array, and each element contained in {<var>obj</var>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * is either null or a valid value for the element's open type specified
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   556
     * by this {@code ArrayType} instance.</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param obj the object to be tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   561
     * @return {@code true} if <var>obj</var> is a value for this
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   562
     * {@code ArrayType} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public boolean isValue(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   572
        Class<?> objClass = obj.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        String objClassName = objClass.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // if obj is not an array, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if ( ! objClass.isArray() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        // Test if obj's class name is the same as for the array values that this instance describes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        // (this is fine if elements are of simple types, which are final classes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if ( this.getClassName().equals(objClassName) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        // In case this ArrayType instance describes an array of classes implementing the TabularData or CompositeData interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        // we first check for the assignability of obj to such an array of TabularData or CompositeData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        // which ensures that:
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 27957
diff changeset
   591
        //  . obj is of the same dimension as this ArrayType instance,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        //  . it is declared as an array of elements which are either all TabularData or all CompositeData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        // If the assignment check is positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // then we have to check that each element in obj is of the same TabularType or CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // as the one described by this ArrayType instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        // [About assignment check, note that the call below returns true: ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        // [Class.forName("[Lpackage.CompositeData;").isAssignableFrom(Class.forName("[Lpackage.CompositeDataImpl;)")); ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if ( (this.elementType.getClassName().equals(TabularData.class.getName()))  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
             (this.elementType.getClassName().equals(CompositeData.class.getName()))   ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            boolean isTabular =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                (elementType.getClassName().equals(TabularData.class.getName()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            int[] dims = new int[getDimension()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            Class<?> elementClass = isTabular ? TabularData.class : CompositeData.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            Class<?> targetClass = Array.newInstance(elementClass, dims).getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            // assignment check: return false if negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if  ( ! targetClass.isAssignableFrom(objClass) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            // check that all elements in obj are valid values for this ArrayType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if ( ! checkElementsType( (Object[]) obj, this.dimension) ) { // we know obj's dimension is this.dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        // if previous tests did not return, then obj is not a value for this ArrayType instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Returns true if and only if all elements contained in the array argument x_dim_Array of dimension dim
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * are valid values (ie either null or of the right openType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * for the element open type specified by this ArrayType instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * This method's implementation uses recursion to go down the dimensions of the array argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    private boolean checkElementsType(Object[] x_dim_Array, int dim) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // if the elements of x_dim_Array are themselves array: go down recursively....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if ( dim > 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            for (int i=0; i<x_dim_Array.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                if ( ! checkElementsType((Object[])x_dim_Array[i], dim-1) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // ...else, for a non-empty array, each element must be a valid value: either null or of the right openType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            for (int i=0; i<x_dim_Array.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                if ( (x_dim_Array[i] != null) && (! this.getElementOpenType().isValue(x_dim_Array[i])) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    @Override
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   657
    boolean isAssignableFrom(OpenType<?> ot) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   658
        if (!(ot instanceof ArrayType<?>))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        ArrayType<?> at = (ArrayType<?>) ot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return (at.getDimension() == getDimension() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                at.isPrimitiveArray() == isPrimitiveArray() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                at.getElementOpenType().isAssignableFrom(getElementOpenType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /* *** Methods overriden from class Object *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   670
     * Compares the specified {@code obj} parameter with this
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   671
     * {@code ArrayType} instance for equality.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   673
     * Two {@code ArrayType} instances are equal if and only if they
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * describe array instances which have the same dimension, elements'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * open type and primitive array flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @param obj the object to be compared for equality with this
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   678
     *            {@code ArrayType} instance; if <var>obj</var>
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   679
     *            is {@code null} or is not an instance of the
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   680
     *            class {@code ArrayType} this method returns
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   681
     *            {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   683
     * @return {@code true} if the specified object is equal to
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   684
     *         this {@code ArrayType} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        // if obj is not an ArrayType, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        //
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   696
        if (!(obj instanceof ArrayType<?>))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            return false;
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   698
        ArrayType<?> other = (ArrayType<?>) obj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        // if other's dimension is different than this instance's, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (this.dimension != other.dimension) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        // Test if other's elementType field is the same as for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if (!this.elementType.equals(other.elementType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // Test if other's primitiveArray flag is the same as for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        return this.primitiveArray == other.primitiveArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   718
     * Returns the hash code value for this {@code ArrayType} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   720
     * The hash code of an {@code ArrayType} instance is the sum of the
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   721
     * hash codes of all the elements of information used in {@code equals}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * comparisons (i.e. dimension, elements' open type and primitive array flag).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * The hashcode for a primitive value is the hashcode of the corresponding boxed
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   724
     * object (e.g. the hashcode for {@code true} is {@code Boolean.TRUE.hashCode()}).
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   725
     * This ensures that {@code t1.equals(t2)} implies that
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   726
     * {@code t1.hashCode()==t2.hashCode()} for any two
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   727
     * {@code ArrayType} instances {@code t1} and {@code t2},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * as required by the general contract of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * {@link Object#hashCode() Object.hashCode()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   731
     * As {@code ArrayType} instances are immutable, the hash
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * code for this instance is calculated once, on the first call
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   733
     * to {@code hashCode}, and then the same value is returned
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * for subsequent calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   736
     * @return  the hash code value for this {@code ArrayType} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            value += dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            value += elementType.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            value += Boolean.valueOf(primitiveArray).hashCode();
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   747
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   756
     * Returns a string representation of this {@code ArrayType} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * The string representation consists of the name of this class (i.e.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   759
     * {@code javax.management.openmbean.ArrayType}), the type name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * the dimension, the elements' open type and the primitive array flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * defined for this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * <p>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   763
     * As {@code ArrayType} instances are immutable, the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * string representation for this instance is calculated
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   765
     * once, on the first call to {@code toString}, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * then the same value is returned for subsequent calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   768
     * @return a string representation of this {@code ArrayType} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        // Calculate the string representation if it has not yet been done (ie 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            myToString = getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                         "(name=" + getTypeName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                         ",dimension=" + dimension +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                         ",elementType=" + elementType +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                         ",primitiveArray=" + primitiveArray + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        // return always the same string representation for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Create an {@code ArrayType} instance in a type-safe manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Multidimensional arrays can be built up by calling this method as many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * times as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Calling this method twice with the same parameters may return the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * object or two equal but not identical objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * As an example, the following piece of code:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   797
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * ArrayType<String[]> t1 = ArrayType.getArrayType(SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * ArrayType<String[][]> t2 = ArrayType.getArrayType(t1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * ArrayType<String[][][]> t3 = ArrayType.getArrayType(t2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * System.out.println("array class name       = " + t3.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * System.out.println("element class name     = " + t3.getElementOpenType().getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * System.out.println("array type name        = " + t3.getTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * System.out.println("array type description = " + t3.getDescription());
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   805
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * would produce the following output:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   807
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * array class name       = [[[Ljava.lang.String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * element class name     = java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * array type name        = [[[Ljava.lang.String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * array type description = 3-dimension array of java.lang.String
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   812
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 28059
diff changeset
   814
     * @param <E> the Java type that described instances must have
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @param  elementType  the <i>open type</i> of element values contained
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   816
     *                      in the arrays described by this {@code ArrayType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *                      instance; must be an instance of either
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   818
     *                      {@code SimpleType}, {@code CompositeType},
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   819
     *                      {@code TabularType} or another {@code ArrayType}
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   820
     *                      with a {@code SimpleType}, {@code CompositeType}
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 29927
diff changeset
   821
     *                      or {@code TabularType} as its {@code elementType}.
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 28059
diff changeset
   822
     * @return an {@code ArrayType} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @throws OpenDataException if <var>elementType's className</var> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *                           one of the allowed Java class names for open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *                           data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public static <E> ArrayType<E[]> getArrayType(OpenType<E> elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        return new ArrayType<E[]>(1, elementType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * Create an {@code ArrayType} instance in a type-safe manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * Calling this method twice with the same parameters may return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * same object or two equal but not identical objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * As an example, the following piece of code:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   841
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * ArrayType<int[][][]> t = ArrayType.getPrimitiveArrayType(int[][][].class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * System.out.println("array class name       = " + t.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * System.out.println("element class name     = " + t.getElementOpenType().getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * System.out.println("array type name        = " + t.getTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * System.out.println("array type description = " + t.getDescription());
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   847
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * would produce the following output:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   849
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * array class name       = [[[I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * element class name     = java.lang.Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * array type name        = [[[I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * array type description = 3-dimension array of int
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   854
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 28059
diff changeset
   856
     * @param <T> the Java type that described instances must have
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @param arrayClass a primitive array class such as {@code int[].class},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *                   {@code boolean[][].class}, etc. The {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *                   #getElementOpenType()} method of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *                   {@code ArrayType} returns the {@link SimpleType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *                   corresponding to the wrapper type of the primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *                   type of the array.
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 28059
diff changeset
   863
     * @return an {@code ArrayType} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @throws IllegalArgumentException if <var>arrayClass</var> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *                                  a primitive array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    @SuppressWarnings("unchecked")  // can't get appropriate T for primitive array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public static <T> ArrayType<T> getPrimitiveArrayType(Class<T> arrayClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        // Check if the supplied parameter is an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (!arrayClass.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            throw new IllegalArgumentException("arrayClass must be an array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        // Calculate array dimension and component type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        int n = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        Class<?> componentType = arrayClass.getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        while (componentType.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            n++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            componentType = componentType.getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        String componentTypeName = componentType.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        // Check if the array's component type is a primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        if (!componentType.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                "component type of the array must be a primitive type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        // Map component type name to corresponding SimpleType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        final SimpleType<?> simpleType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                getPrimitiveOpenType(componentTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        // Build primitive array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        try {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   903
            @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            ArrayType at = new ArrayType(simpleType, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            if (n > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                at = new ArrayType<T>(n - 1, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            return at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            throw new IllegalArgumentException(e); // should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * Replace/resolve the object read from the stream before it is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * to the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @serialData The new serial form of this class defines a new serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * {@code boolean} field {@code primitiveArray}. In order to guarantee the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * interoperability with previous versions of this class the new serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * form must continue to refer to primitive wrapper types even when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * {@code ArrayType} instance describes a primitive type array. So when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * {@code primitiveArray} is {@code true} the {@code className},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * {@code typeName} and {@code description} serializable fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * are converted into primitive types before the deserialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * {@code ArrayType} instance is return to the caller. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * {@code elementType} field always returns the {@code SimpleType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * corresponding to the primitive wrapper type of the array's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Therefore the following serializable fields are deserialized as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *   <li>if {@code primitiveArray} is {@code true} the {@code className}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *       field is deserialized by replacing the array's component primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     *       wrapper type by the corresponding array's component primitive type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     *       e.g. {@code "[[Ljava.lang.Integer;"} will be deserialized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     *       {@code "[[I"}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     *   <li>if {@code primitiveArray} is {@code true} the {@code typeName}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *       field is deserialized by replacing the array's component primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *       wrapper type by the corresponding array's component primitive type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *       e.g. {@code "[[Ljava.lang.Integer;"} will be deserialized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     *       {@code "[[I"}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     *   <li>if {@code primitiveArray} is {@code true} the {@code description}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *       field is deserialized by replacing the array's component primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *       wrapper type by the corresponding array's component primitive type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *       e.g. {@code "2-dimension array of java.lang.Integer"} will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     *       deserialized as {@code "2-dimension array of int"}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    private Object readResolve() throws ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if (primitiveArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            return convertFromWrapperToPrimitiveTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   959
    private <T> ArrayType<T> convertFromWrapperToPrimitiveTypes() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        String cn = getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        String tn = getTypeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        String d = getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if (cn.indexOf((String)typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                cn = cn.replaceFirst(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    "L" + typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX] + ";",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    (String) typeDescr[PRIMITIVE_TYPE_KEY_INDEX]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                tn = tn.replaceFirst(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    "L" + typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX] + ";",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    (String) typeDescr[PRIMITIVE_TYPE_KEY_INDEX]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                d = d.replaceFirst(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    (String) typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    (String) typeDescr[PRIMITIVE_TYPE_NAME_INDEX]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        }
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   977
        return new ArrayType<T>(cn, tn, d,
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   978
                                dimension, elementType, primitiveArray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * Nominate a replacement for this object in the stream before the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @serialData The new serial form of this class defines a new serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * {@code boolean} field {@code primitiveArray}. In order to guarantee the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * interoperability with previous versions of this class the new serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * form must continue to refer to primitive wrapper types even when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * {@code ArrayType} instance describes a primitive type array. So when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * {@code primitiveArray} is {@code true} the {@code className},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * {@code typeName} and {@code description} serializable fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * are converted into wrapper types before the serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * {@code ArrayType} instance is written to the stream. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * {@code elementType} field always returns the {@code SimpleType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * corresponding to the primitive wrapper type of the array's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * Therefore the following serializable fields are serialized as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *   <li>if {@code primitiveArray} is {@code true} the {@code className}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *       field is serialized by replacing the array's component primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     *       type by the corresponding array's component primitive wrapper type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *       e.g. {@code "[[I"} will be serialized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     *       {@code "[[Ljava.lang.Integer;"}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *   <li>if {@code primitiveArray} is {@code true} the {@code typeName}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *       field is serialized by replacing the array's component primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *       type by the corresponding array's component primitive wrapper type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *       e.g. {@code "[[I"} will be serialized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     *       {@code "[[Ljava.lang.Integer;"}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *   <li>if {@code primitiveArray} is {@code true} the {@code description}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *       field is serialized by replacing the array's component primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *       type by the corresponding array's component primitive wrapper type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *       e.g. {@code "2-dimension array of int"} will be serialized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *       {@code "2-dimension array of java.lang.Integer"}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    private Object writeReplace() throws ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        if (primitiveArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            return convertFromPrimitiveToWrapperTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
  1027
    private <T> ArrayType<T> convertFromPrimitiveToWrapperTypes() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        String cn = getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        String tn = getTypeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        String d = getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            if (cn.indexOf((String) typeDescr[PRIMITIVE_TYPE_KEY_INDEX]) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                cn = cn.replaceFirst(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    (String) typeDescr[PRIMITIVE_TYPE_KEY_INDEX],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    "L" + typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX] + ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                tn = tn.replaceFirst(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    (String) typeDescr[PRIMITIVE_TYPE_KEY_INDEX],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                    "L" + typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX] + ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                d = d.replaceFirst(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    (String) typeDescr[PRIMITIVE_TYPE_NAME_INDEX],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    (String) typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        }
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
  1045
        return new ArrayType<T>(cn, tn, d,
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
  1046
                                dimension, elementType, primitiveArray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
}