@Beta public class ExpandableArray<E> extends Object implements Serializable, Iterable<E>, Comparable<ExpandableArray>
How does this differ from ArrayList, you ask? Well, it behaves like an array and not a list (and thus does not implement List). While an ArrayList will shift values right to fit new values, an ExpandableArray will simply overwrite values. And while if you try to set at a value past the end of an array list, you'll get an ArrayIndexOutOfBounds exception, if you do it on an ExpandableArray, it will happily set it for you. This is fairly similar to an IntHashMap, but more lightweight. Examples:
arrayList.set(0, two);
arrayList.set(0, one);
arrayList.set(0, zero);
arrayList.get(0) == zero
arrayList.get(1) == one
arrayList.get(2) == two
but:
expandableArray.set(0, two);
expandableArray.set(0, one);
expandableArray.set(0, zero);
expandableArray.get(0) == zero
expandableArray.get(1) == null
expandableArray.get(2) == null
and:
arrayList.set(99, ninetyNine); // throws ArrayIndexOutOfBounds
but:
expandableArray.set(99, ninetyNine);
expandableArray.get(99) == ninetyNine
Beta class. Classes under com.force.i18n.commons package will be moved into a dedicated project.| Constructor and Description |
|---|
ExpandableArray() |
ExpandableArray(E[] m) |
ExpandableArray(ExpandableArray<? extends E> m) |
ExpandableArray(int initialSize) |
ExpandableArray(int initialSize,
float factor) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
int |
compareTo(ExpandableArray other) |
static <V> ExpandableArray<V> |
create(int initialSize) |
boolean |
equals(Object other) |
E |
get(int index) |
int |
hashCode() |
Iterator<E> |
iterator() |
void |
makeUnmodifiable()
Makes the expandable array immutable.
|
static <T> T[] |
resizeArray(T[] array,
int size)
Helper to resize any array.
|
void |
set(int index,
E value) |
int |
size()
Returns 1 + the index of the highest non-null value.
|
static <T> T[] |
subArray(T[] array,
int start,
int end)
Helper to get the sub-array of any array.
|
Object[] |
toArray()
Returns an array containing all of the elements in this list
in the correct order.
|
<T> T[] |
toArray(Class<T> clazz)
Returns an array containing all of the elements in this list
in the correct order.
|
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this list in the
correct order; the runtime type of the returned array is that of the
specified array.
|
String |
toString() |
void |
trimToSize()
Trims the capacity of this ExpandableArray instance to be the
arrays's current size.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic ExpandableArray()
public ExpandableArray(int initialSize)
public ExpandableArray(int initialSize,
float factor)
public ExpandableArray(ExpandableArray<? extends E> m)
public ExpandableArray(E[] m)
public static <V> ExpandableArray<V> create(int initialSize)
public void makeUnmodifiable()
public E get(int index)
public void set(int index,
E value)
public void trimToSize()
public int size()
public void clear()
public Object[] toArray()
public <T> T[] toArray(T[] a)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.
a - the array into which the elements of the list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.ArrayStoreException - if the runtime type of a is not a supertype
of the runtime type of every element in this list.public <T> T[] toArray(Class<T> clazz)
clazz - the class of the array that should be constructed
to hold the element.public static <T> T[] resizeArray(T[] array,
int size)
size is exactly the
length of array, it returns array.
Otherwise, it will return a new array.
Returns an array of size size containing the first
size elements in array. If size is
greater than the length of array, the remaining
elements in the resulting array will be null.public static <T> T[] subArray(T[] array,
int start,
int end)
start is 0 and
end is length of array, it returns array.
Otherwise, it will return a new array.
Returns an array containing the elements from start inclusive
to end exclusive. The resulting array will be of size end - start.
If end is greater than the size of the array, it will create a
result array with nulls in those spots.public int compareTo(ExpandableArray other)
compareTo in interface Comparable<ExpandableArray>Copyright (c) 2016-2017, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE.txt file in the repository.