public final class Array extends Object
Modifier and Type | Field and Description |
---|---|
protected int |
queryId
A representation of the necessary cast target for objects stored into this
array.
|
Constructor and Description |
---|
Array() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
clone(T[] array)
Creates a copy of the specified array.
|
static <T> T[] |
cloneSubrange(T[] array,
int fromIndex,
int toIndex)
Creates a copy of a subrange of the specified array.
|
static <T> T[] |
createFrom(T[] array)
Creates a new array of the exact same type and length as a given array.
|
static <T> T[] |
createFrom(T[] array,
int length)
Creates an empty array of the exact same type as a given array, with the
specified length.
|
static Array |
initDim(Class<?> arrayClass,
JavaScriptObject castableTypeMap,
int queryId,
int length,
int seedType)
Creates an array like "new T[a][b][c][][]" by passing in a native JSON
array, [a, b, c].
|
static Array |
initDims(Class<?>[] arrayClasses,
JavaScriptObject[] castableTypeMapExprs,
int[] queryIdExprs,
int[] dimExprs,
int count,
int seedType)
Creates an array like "new T[a][b][c][][]" by passing in a native JSON
array, [a, b, c].
|
static Array |
initValues(Class<?> arrayClass,
JavaScriptObject castableTypeMap,
int queryId,
Array array)
Creates an array like "new T[][]{a,b,c,d}" by passing in a native JSON
array, [a, b, c, d].
|
static Object |
setCheck(Array array,
int index,
Object value)
Performs an array assignment, after validating the type of the value being
stored.
|
protected int queryId
public static <T> T[] clone(T[] array)
public static <T> T[] cloneSubrange(T[] array, int fromIndex, int toIndex)
public static <T> T[] createFrom(T[] array)
public static <T> T[] createFrom(T[] array, int length)
public static Array initDim(Class<?> arrayClass, JavaScriptObject castableTypeMap, int queryId, int length, int seedType)
arrayClass
- the class of the arraycastableTypeMap
- the map of types to which this array can be casted,
in the form of a JSON map objectqueryId
- the queryId of the arraylength
- the length of the arrayseedType
- the primitive type of the array; 0: null; 1: zero; 2: false; 3: longpublic static Array initDims(Class<?>[] arrayClasses, JavaScriptObject[] castableTypeMapExprs, int[] queryIdExprs, int[] dimExprs, int count, int seedType)
arrayClasses
- the class of each dimension of the arraycastableTypeMapExprs
- the JSON castableTypeMap of each dimension,
from highest to lowestqueryIdExprs
- the queryId of each dimension, from highest to lowestdimExprs
- the length of each dimension, from highest to lowerseedType
- the primitive type of the array; 0: null; 1: zero; 2: false; 3: longpublic static Array initValues(Class<?> arrayClass, JavaScriptObject castableTypeMap, int queryId, Array array)
arrayClass
- the class of the arraycastableTypeMap
- the map of types to which this array can be casted,
in the form of a JSON map objectqueryId
- the queryId of the arrayarray
- the JSON array that will be transformed into a GWT arraypublic static Object setCheck(Array array, int index, Object value)
If the queryId is > 0, this indicates a normal cast check should be performed, using the queryId as the cast destination type. JavaScriptObjects cannot be stored in this case.
If the queryId == 0, this is the cast target for the Object type, in which case all types can be stored, including JavaScriptObject.
If the queryId == -1, this indicates that only JavaScriptObjects can be stored (-1 is the cast target for JavaScriptObject, by convention).
If the queryId is < -1, this indicates that both JavaScriptObjects, and Java types can be stored. In the case of Java types, the inverse of the queryId is used for castability testing. This case is provided to support arrays declared with an interface type, which has dual implementations (i.e. interface types which have both Java and JavaScriptObject implementations).
Note, by convention, a queryId of 1 is reserved for String, which is a final class, and can't implement an interface, and thus, it's inverse, -1, can safely be interpreted as a special case, as stated above.
Attempting to store an object that cannot satisfy the castability check
throws an ArrayStoreException
.
Copyright © 2018. All rights reserved.