emul/src/main/java/java/lang/reflect/Array.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 18 Jan 2013 12:07:11 +0100
branchjdk7-b147
changeset 475 1a61b103ac45
child 477 22e99afe5083
permissions -rw-r--r--
Will replace direct manipulation with arrays with calls to java.lang.reflect.Array
jaroslav@475
     1
/*
jaroslav@475
     2
 * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
jaroslav@475
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@475
     4
 *
jaroslav@475
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@475
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@475
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@475
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@475
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@475
    10
 *
jaroslav@475
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@475
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@475
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@475
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@475
    15
 * accompanied this code).
jaroslav@475
    16
 *
jaroslav@475
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@475
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@475
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@475
    20
 *
jaroslav@475
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@475
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@475
    23
 * questions.
jaroslav@475
    24
 */
jaroslav@475
    25
jaroslav@475
    26
package java.lang.reflect;
jaroslav@475
    27
jaroslav@475
    28
/**
jaroslav@475
    29
 * The {@code Array} class provides static methods to dynamically create and
jaroslav@475
    30
 * access Java arrays.
jaroslav@475
    31
 *
jaroslav@475
    32
 * <p>{@code Array} permits widening conversions to occur during a get or set
jaroslav@475
    33
 * operation, but throws an {@code IllegalArgumentException} if a narrowing
jaroslav@475
    34
 * conversion would occur.
jaroslav@475
    35
 *
jaroslav@475
    36
 * @author Nakul Saraiya
jaroslav@475
    37
 */
jaroslav@475
    38
public final
jaroslav@475
    39
class Array {
jaroslav@475
    40
jaroslav@475
    41
    /**
jaroslav@475
    42
     * Constructor.  Class Array is not instantiable.
jaroslav@475
    43
     */
jaroslav@475
    44
    private Array() {}
jaroslav@475
    45
jaroslav@475
    46
    /**
jaroslav@475
    47
     * Creates a new array with the specified component type and
jaroslav@475
    48
     * length.
jaroslav@475
    49
     * Invoking this method is equivalent to creating an array
jaroslav@475
    50
     * as follows:
jaroslav@475
    51
     * <blockquote>
jaroslav@475
    52
     * <pre>
jaroslav@475
    53
     * int[] x = {length};
jaroslav@475
    54
     * Array.newInstance(componentType, x);
jaroslav@475
    55
     * </pre>
jaroslav@475
    56
     * </blockquote>
jaroslav@475
    57
     *
jaroslav@475
    58
     * @param componentType the {@code Class} object representing the
jaroslav@475
    59
     * component type of the new array
jaroslav@475
    60
     * @param length the length of the new array
jaroslav@475
    61
     * @return the new array
jaroslav@475
    62
     * @exception NullPointerException if the specified
jaroslav@475
    63
     * {@code componentType} parameter is null
jaroslav@475
    64
     * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
jaroslav@475
    65
     * @exception NegativeArraySizeException if the specified {@code length}
jaroslav@475
    66
     * is negative
jaroslav@475
    67
     */
jaroslav@475
    68
    public static Object newInstance(Class<?> componentType, int length)
jaroslav@475
    69
        throws NegativeArraySizeException {
jaroslav@475
    70
        return newArray(componentType, length);
jaroslav@475
    71
    }
jaroslav@475
    72
jaroslav@475
    73
    /**
jaroslav@475
    74
     * Creates a new array
jaroslav@475
    75
     * with the specified component type and dimensions.
jaroslav@475
    76
     * If {@code componentType}
jaroslav@475
    77
     * represents a non-array class or interface, the new array
jaroslav@475
    78
     * has {@code dimensions.length} dimensions and
jaroslav@475
    79
     * {@code componentType} as its component type. If
jaroslav@475
    80
     * {@code componentType} represents an array class, the
jaroslav@475
    81
     * number of dimensions of the new array is equal to the sum
jaroslav@475
    82
     * of {@code dimensions.length} and the number of
jaroslav@475
    83
     * dimensions of {@code componentType}. In this case, the
jaroslav@475
    84
     * component type of the new array is the component type of
jaroslav@475
    85
     * {@code componentType}.
jaroslav@475
    86
     *
jaroslav@475
    87
     * <p>The number of dimensions of the new array must not
jaroslav@475
    88
     * exceed the number of array dimensions supported by the
jaroslav@475
    89
     * implementation (typically 255).
jaroslav@475
    90
     *
jaroslav@475
    91
     * @param componentType the {@code Class} object representing the component
jaroslav@475
    92
     * type of the new array
jaroslav@475
    93
     * @param dimensions an array of {@code int} representing the dimensions of
jaroslav@475
    94
     * the new array
jaroslav@475
    95
     * @return the new array
jaroslav@475
    96
     * @exception NullPointerException if the specified
jaroslav@475
    97
     * {@code componentType} argument is null
jaroslav@475
    98
     * @exception IllegalArgumentException if the specified {@code dimensions}
jaroslav@475
    99
     * argument is a zero-dimensional array, or if the number of
jaroslav@475
   100
     * requested dimensions exceeds the limit on the number of array dimensions
jaroslav@475
   101
     * supported by the implementation (typically 255), or if componentType
jaroslav@475
   102
     * is {@link Void#TYPE}.
jaroslav@475
   103
     * @exception NegativeArraySizeException if any of the components in
jaroslav@475
   104
     * the specified {@code dimensions} argument is negative.
jaroslav@475
   105
     */
jaroslav@475
   106
    public static Object newInstance(Class<?> componentType, int... dimensions)
jaroslav@475
   107
        throws IllegalArgumentException, NegativeArraySizeException {
jaroslav@475
   108
        return multiNewArray(componentType, dimensions);
jaroslav@475
   109
    }
jaroslav@475
   110
jaroslav@475
   111
    /**
jaroslav@475
   112
     * Returns the length of the specified array object, as an {@code int}.
jaroslav@475
   113
     *
jaroslav@475
   114
     * @param array the array
jaroslav@475
   115
     * @return the length of the array
jaroslav@475
   116
     * @exception IllegalArgumentException if the object argument is not
jaroslav@475
   117
     * an array
jaroslav@475
   118
     */
jaroslav@475
   119
    public static native int getLength(Object array)
jaroslav@475
   120
        throws IllegalArgumentException;
jaroslav@475
   121
jaroslav@475
   122
    /**
jaroslav@475
   123
     * Returns the value of the indexed component in the specified
jaroslav@475
   124
     * array object.  The value is automatically wrapped in an object
jaroslav@475
   125
     * if it has a primitive type.
jaroslav@475
   126
     *
jaroslav@475
   127
     * @param array the array
jaroslav@475
   128
     * @param index the index
jaroslav@475
   129
     * @return the (possibly wrapped) value of the indexed component in
jaroslav@475
   130
     * the specified array
jaroslav@475
   131
     * @exception NullPointerException If the specified object is null
jaroslav@475
   132
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   133
     * an array
jaroslav@475
   134
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   135
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   136
     * length of the specified array
jaroslav@475
   137
     */
jaroslav@475
   138
    public static native Object get(Object array, int index)
jaroslav@475
   139
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   140
jaroslav@475
   141
    /**
jaroslav@475
   142
     * Returns the value of the indexed component in the specified
jaroslav@475
   143
     * array object, as a {@code boolean}.
jaroslav@475
   144
     *
jaroslav@475
   145
     * @param array the array
jaroslav@475
   146
     * @param index the index
jaroslav@475
   147
     * @return the value of the indexed component in the specified array
jaroslav@475
   148
     * @exception NullPointerException If the specified object is null
jaroslav@475
   149
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   150
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   151
     * return type by an identity or widening conversion
jaroslav@475
   152
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   153
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   154
     * length of the specified array
jaroslav@475
   155
     * @see Array#get
jaroslav@475
   156
     */
jaroslav@475
   157
    public static native boolean getBoolean(Object array, int index)
jaroslav@475
   158
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   159
jaroslav@475
   160
    /**
jaroslav@475
   161
     * Returns the value of the indexed component in the specified
jaroslav@475
   162
     * array object, as a {@code byte}.
jaroslav@475
   163
     *
jaroslav@475
   164
     * @param array the array
jaroslav@475
   165
     * @param index the index
jaroslav@475
   166
     * @return the value of the indexed component in the specified array
jaroslav@475
   167
     * @exception NullPointerException If the specified object is null
jaroslav@475
   168
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   169
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   170
     * return type by an identity or widening conversion
jaroslav@475
   171
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   172
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   173
     * length of the specified array
jaroslav@475
   174
     * @see Array#get
jaroslav@475
   175
     */
jaroslav@475
   176
    public static native byte getByte(Object array, int index)
jaroslav@475
   177
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   178
jaroslav@475
   179
    /**
jaroslav@475
   180
     * Returns the value of the indexed component in the specified
jaroslav@475
   181
     * array object, as a {@code char}.
jaroslav@475
   182
     *
jaroslav@475
   183
     * @param array the array
jaroslav@475
   184
     * @param index the index
jaroslav@475
   185
     * @return the value of the indexed component in the specified array
jaroslav@475
   186
     * @exception NullPointerException If the specified object is null
jaroslav@475
   187
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   188
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   189
     * return type by an identity or widening conversion
jaroslav@475
   190
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   191
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   192
     * length of the specified array
jaroslav@475
   193
     * @see Array#get
jaroslav@475
   194
     */
jaroslav@475
   195
    public static native char getChar(Object array, int index)
jaroslav@475
   196
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   197
jaroslav@475
   198
    /**
jaroslav@475
   199
     * Returns the value of the indexed component in the specified
jaroslav@475
   200
     * array object, as a {@code short}.
jaroslav@475
   201
     *
jaroslav@475
   202
     * @param array the array
jaroslav@475
   203
     * @param index the index
jaroslav@475
   204
     * @return the value of the indexed component in the specified array
jaroslav@475
   205
     * @exception NullPointerException If the specified object is null
jaroslav@475
   206
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   207
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   208
     * return type by an identity or widening conversion
jaroslav@475
   209
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   210
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   211
     * length of the specified array
jaroslav@475
   212
     * @see Array#get
jaroslav@475
   213
     */
jaroslav@475
   214
    public static native short getShort(Object array, int index)
jaroslav@475
   215
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   216
jaroslav@475
   217
    /**
jaroslav@475
   218
     * Returns the value of the indexed component in the specified
jaroslav@475
   219
     * array object, as an {@code int}.
jaroslav@475
   220
     *
jaroslav@475
   221
     * @param array the array
jaroslav@475
   222
     * @param index the index
jaroslav@475
   223
     * @return the value of the indexed component in the specified array
jaroslav@475
   224
     * @exception NullPointerException If the specified object is null
jaroslav@475
   225
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   226
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   227
     * return type by an identity or widening conversion
jaroslav@475
   228
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   229
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   230
     * length of the specified array
jaroslav@475
   231
     * @see Array#get
jaroslav@475
   232
     */
jaroslav@475
   233
    public static native int getInt(Object array, int index)
jaroslav@475
   234
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   235
jaroslav@475
   236
    /**
jaroslav@475
   237
     * Returns the value of the indexed component in the specified
jaroslav@475
   238
     * array object, as a {@code long}.
jaroslav@475
   239
     *
jaroslav@475
   240
     * @param array the array
jaroslav@475
   241
     * @param index the index
jaroslav@475
   242
     * @return the value of the indexed component in the specified array
jaroslav@475
   243
     * @exception NullPointerException If the specified object is null
jaroslav@475
   244
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   245
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   246
     * return type by an identity or widening conversion
jaroslav@475
   247
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   248
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   249
     * length of the specified array
jaroslav@475
   250
     * @see Array#get
jaroslav@475
   251
     */
jaroslav@475
   252
    public static native long getLong(Object array, int index)
jaroslav@475
   253
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   254
jaroslav@475
   255
    /**
jaroslav@475
   256
     * Returns the value of the indexed component in the specified
jaroslav@475
   257
     * array object, as a {@code float}.
jaroslav@475
   258
     *
jaroslav@475
   259
     * @param array the array
jaroslav@475
   260
     * @param index the index
jaroslav@475
   261
     * @return the value of the indexed component in the specified array
jaroslav@475
   262
     * @exception NullPointerException If the specified object is null
jaroslav@475
   263
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   264
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   265
     * return type by an identity or widening conversion
jaroslav@475
   266
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   267
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   268
     * length of the specified array
jaroslav@475
   269
     * @see Array#get
jaroslav@475
   270
     */
jaroslav@475
   271
    public static native float getFloat(Object array, int index)
jaroslav@475
   272
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   273
jaroslav@475
   274
    /**
jaroslav@475
   275
     * Returns the value of the indexed component in the specified
jaroslav@475
   276
     * array object, as a {@code double}.
jaroslav@475
   277
     *
jaroslav@475
   278
     * @param array the array
jaroslav@475
   279
     * @param index the index
jaroslav@475
   280
     * @return the value of the indexed component in the specified array
jaroslav@475
   281
     * @exception NullPointerException If the specified object is null
jaroslav@475
   282
     * @exception IllegalArgumentException If the specified object is not
jaroslav@475
   283
     * an array, or if the indexed element cannot be converted to the
jaroslav@475
   284
     * return type by an identity or widening conversion
jaroslav@475
   285
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   286
     * argument is negative, or if it is greater than or equal to the
jaroslav@475
   287
     * length of the specified array
jaroslav@475
   288
     * @see Array#get
jaroslav@475
   289
     */
jaroslav@475
   290
    public static native double getDouble(Object array, int index)
jaroslav@475
   291
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   292
jaroslav@475
   293
    /**
jaroslav@475
   294
     * Sets the value of the indexed component of the specified array
jaroslav@475
   295
     * object to the specified new value.  The new value is first
jaroslav@475
   296
     * automatically unwrapped if the array has a primitive component
jaroslav@475
   297
     * type.
jaroslav@475
   298
     * @param array the array
jaroslav@475
   299
     * @param index the index into the array
jaroslav@475
   300
     * @param value the new value of the indexed component
jaroslav@475
   301
     * @exception NullPointerException If the specified object argument
jaroslav@475
   302
     * is null
jaroslav@475
   303
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   304
     * is not an array, or if the array component type is primitive and
jaroslav@475
   305
     * an unwrapping conversion fails
jaroslav@475
   306
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   307
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   308
     * the length of the specified array
jaroslav@475
   309
     */
jaroslav@475
   310
    public static native void set(Object array, int index, Object value)
jaroslav@475
   311
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   312
jaroslav@475
   313
    /**
jaroslav@475
   314
     * Sets the value of the indexed component of the specified array
jaroslav@475
   315
     * object to the specified {@code boolean} value.
jaroslav@475
   316
     * @param array the array
jaroslav@475
   317
     * @param index the index into the array
jaroslav@475
   318
     * @param z the new value of the indexed component
jaroslav@475
   319
     * @exception NullPointerException If the specified object argument
jaroslav@475
   320
     * is null
jaroslav@475
   321
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   322
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   323
     * to the underlying array's component type by an identity or a
jaroslav@475
   324
     * primitive widening conversion
jaroslav@475
   325
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   326
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   327
     * the length of the specified array
jaroslav@475
   328
     * @see Array#set
jaroslav@475
   329
     */
jaroslav@475
   330
    public static native void setBoolean(Object array, int index, boolean z)
jaroslav@475
   331
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   332
jaroslav@475
   333
    /**
jaroslav@475
   334
     * Sets the value of the indexed component of the specified array
jaroslav@475
   335
     * object to the specified {@code byte} value.
jaroslav@475
   336
     * @param array the array
jaroslav@475
   337
     * @param index the index into the array
jaroslav@475
   338
     * @param b the new value of the indexed component
jaroslav@475
   339
     * @exception NullPointerException If the specified object argument
jaroslav@475
   340
     * is null
jaroslav@475
   341
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   342
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   343
     * to the underlying array's component type by an identity or a
jaroslav@475
   344
     * primitive widening conversion
jaroslav@475
   345
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   346
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   347
     * the length of the specified array
jaroslav@475
   348
     * @see Array#set
jaroslav@475
   349
     */
jaroslav@475
   350
    public static native void setByte(Object array, int index, byte b)
jaroslav@475
   351
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   352
jaroslav@475
   353
    /**
jaroslav@475
   354
     * Sets the value of the indexed component of the specified array
jaroslav@475
   355
     * object to the specified {@code char} value.
jaroslav@475
   356
     * @param array the array
jaroslav@475
   357
     * @param index the index into the array
jaroslav@475
   358
     * @param c the new value of the indexed component
jaroslav@475
   359
     * @exception NullPointerException If the specified object argument
jaroslav@475
   360
     * is null
jaroslav@475
   361
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   362
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   363
     * to the underlying array's component type by an identity or a
jaroslav@475
   364
     * primitive widening conversion
jaroslav@475
   365
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   366
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   367
     * the length of the specified array
jaroslav@475
   368
     * @see Array#set
jaroslav@475
   369
     */
jaroslav@475
   370
    public static native void setChar(Object array, int index, char c)
jaroslav@475
   371
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   372
jaroslav@475
   373
    /**
jaroslav@475
   374
     * Sets the value of the indexed component of the specified array
jaroslav@475
   375
     * object to the specified {@code short} value.
jaroslav@475
   376
     * @param array the array
jaroslav@475
   377
     * @param index the index into the array
jaroslav@475
   378
     * @param s the new value of the indexed component
jaroslav@475
   379
     * @exception NullPointerException If the specified object argument
jaroslav@475
   380
     * is null
jaroslav@475
   381
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   382
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   383
     * to the underlying array's component type by an identity or a
jaroslav@475
   384
     * primitive widening conversion
jaroslav@475
   385
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   386
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   387
     * the length of the specified array
jaroslav@475
   388
     * @see Array#set
jaroslav@475
   389
     */
jaroslav@475
   390
    public static native void setShort(Object array, int index, short s)
jaroslav@475
   391
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   392
jaroslav@475
   393
    /**
jaroslav@475
   394
     * Sets the value of the indexed component of the specified array
jaroslav@475
   395
     * object to the specified {@code int} value.
jaroslav@475
   396
     * @param array the array
jaroslav@475
   397
     * @param index the index into the array
jaroslav@475
   398
     * @param i the new value of the indexed component
jaroslav@475
   399
     * @exception NullPointerException If the specified object argument
jaroslav@475
   400
     * is null
jaroslav@475
   401
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   402
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   403
     * to the underlying array's component type by an identity or a
jaroslav@475
   404
     * primitive widening conversion
jaroslav@475
   405
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   406
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   407
     * the length of the specified array
jaroslav@475
   408
     * @see Array#set
jaroslav@475
   409
     */
jaroslav@475
   410
    public static native void setInt(Object array, int index, int i)
jaroslav@475
   411
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   412
jaroslav@475
   413
    /**
jaroslav@475
   414
     * Sets the value of the indexed component of the specified array
jaroslav@475
   415
     * object to the specified {@code long} value.
jaroslav@475
   416
     * @param array the array
jaroslav@475
   417
     * @param index the index into the array
jaroslav@475
   418
     * @param l the new value of the indexed component
jaroslav@475
   419
     * @exception NullPointerException If the specified object argument
jaroslav@475
   420
     * is null
jaroslav@475
   421
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   422
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   423
     * to the underlying array's component type by an identity or a
jaroslav@475
   424
     * primitive widening conversion
jaroslav@475
   425
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   426
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   427
     * the length of the specified array
jaroslav@475
   428
     * @see Array#set
jaroslav@475
   429
     */
jaroslav@475
   430
    public static native void setLong(Object array, int index, long l)
jaroslav@475
   431
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   432
jaroslav@475
   433
    /**
jaroslav@475
   434
     * Sets the value of the indexed component of the specified array
jaroslav@475
   435
     * object to the specified {@code float} value.
jaroslav@475
   436
     * @param array the array
jaroslav@475
   437
     * @param index the index into the array
jaroslav@475
   438
     * @param f the new value of the indexed component
jaroslav@475
   439
     * @exception NullPointerException If the specified object argument
jaroslav@475
   440
     * is null
jaroslav@475
   441
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   442
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   443
     * to the underlying array's component type by an identity or a
jaroslav@475
   444
     * primitive widening conversion
jaroslav@475
   445
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   446
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   447
     * the length of the specified array
jaroslav@475
   448
     * @see Array#set
jaroslav@475
   449
     */
jaroslav@475
   450
    public static native void setFloat(Object array, int index, float f)
jaroslav@475
   451
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   452
jaroslav@475
   453
    /**
jaroslav@475
   454
     * Sets the value of the indexed component of the specified array
jaroslav@475
   455
     * object to the specified {@code double} value.
jaroslav@475
   456
     * @param array the array
jaroslav@475
   457
     * @param index the index into the array
jaroslav@475
   458
     * @param d the new value of the indexed component
jaroslav@475
   459
     * @exception NullPointerException If the specified object argument
jaroslav@475
   460
     * is null
jaroslav@475
   461
     * @exception IllegalArgumentException If the specified object argument
jaroslav@475
   462
     * is not an array, or if the specified value cannot be converted
jaroslav@475
   463
     * to the underlying array's component type by an identity or a
jaroslav@475
   464
     * primitive widening conversion
jaroslav@475
   465
     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
jaroslav@475
   466
     * argument is negative, or if it is greater than or equal to
jaroslav@475
   467
     * the length of the specified array
jaroslav@475
   468
     * @see Array#set
jaroslav@475
   469
     */
jaroslav@475
   470
    public static native void setDouble(Object array, int index, double d)
jaroslav@475
   471
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
jaroslav@475
   472
jaroslav@475
   473
    /*
jaroslav@475
   474
     * Private
jaroslav@475
   475
     */
jaroslav@475
   476
jaroslav@475
   477
    private static native Object newArray(Class componentType, int length)
jaroslav@475
   478
        throws NegativeArraySizeException;
jaroslav@475
   479
jaroslav@475
   480
    private static native Object multiNewArray(Class componentType,
jaroslav@475
   481
        int[] dimensions)
jaroslav@475
   482
        throws IllegalArgumentException, NegativeArraySizeException;
jaroslav@475
   483
jaroslav@475
   484
jaroslav@475
   485
}