|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.erights.e.elib.tables.ArrayHelper
Untamed: Dangerous, for use by trusted code only.
For when you really want to deal with arrays rather than lists for efficiency (or because you're building lists out of arrays), but want to deal with the arrays in an E-like manner.
This class must not be made safe, as it provides public operations that mutate arrays, and that break the encapsulation of lists. Use only with great care, and never to mutate the array inside a list.
Field Summary | |
private static Hashtable |
ArrayTypeMap
|
private static Class[][] |
ArrayTypes
|
Constructor Summary | |
private |
ArrayHelper()
prevents instantiation |
Method Summary | |
static void |
arraycopy(Object src,
int src_position,
Object dst,
int dst_position,
int length)
Enabled: Like System.arraycopy(Object, int, Object, int, int) , but
automatically coerces if necessary, and is void/null tolerant. |
static void |
arraySet(Object array,
int index,
Object val)
Enabled: Like Array.set(Object, int, Object) , but automatically coerces
if necessary, and is void/null tolerant. |
static Object |
getFastArray(EList list)
Enabled: Like list.getArray(), but may provide direct access to the array encapsulated inside a list for speed. |
private static Hashtable |
initArrayTypeMap(int from,
int to)
We use a Hashtable rather than one of our own in order to avoid a circular init-time dependency, since our tables depend on mapping scalar types. |
static Object |
newArray(Class elType,
int size)
Enabled: Like Array.newInstance(Class, int) , but the type is first
converted according to typeForArray(Class) . |
static Object |
resize(Object oldArray,
int newLen)
Enabled: Returns a copy of oldArray but of length newLen. |
static Object |
slice(Object oldArray,
int start,
int bound)
Enabled: Returns a copy of the part of oldArray between start inclusive and bound exclusive. |
static Class |
typeForArray(Class elType)
Enabled: Given a class, return a preferred class for making an array of (abstractly) the kinds of values described by the argument class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final Class[][] ArrayTypes
private static final Hashtable ArrayTypeMap
Constructor Detail |
private ArrayHelper()
Method Detail |
private static Hashtable initArrayTypeMap(int from, int to)
public static Class typeForArray(Class elType)
It maps Void
.TYPE to Void.class.
It maps boxed scalar types, like Integer
.class, to the
corresponding primitive (unboxed) scalar type, like Integer.TYPE.
Otherwise, it just returns its argument.
public static Object newArray(Class elType, int size)
Array.newInstance(Class, int)
, but the type is first
converted according to typeForArray(Class)
.
public static Object getFastArray(EList list)
Use this for good and not for evil. In particular, it must never be used to mutate the array inside a list, or to enable such mutation.
list
-
public static Object resize(Object oldArray, int newLen)
If newLen is larger than the original length, then the extra slots are filled with the zero element for this type. This is null for any Java reference type (and non-primitive class), and 0, '\0', 0.0, or false, as appropriate, for corresponding scalar types.
If newLen is smaller than the original, the extra elements are dropped.
public static Object slice(Object oldArray, int start, int bound)
Like EList.run(int, int)
, but for arrays.
public static void arraySet(Object array, int index, Object val)
Array.set(Object, int, Object)
, but automatically coerces
if necessary, and is void/null tolerant.
public static void arraycopy(Object src, int src_position, Object dst, int dst_position, int length)
System.arraycopy(Object, int, Object, int, int)
, but
automatically coerces if necessary, and is void/null tolerant.
src
- src_position
- dst
- dst_position
- length
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |