Package org.codehaus.groovy.util
Class FastArray
java.lang.Object
org.codehaus.groovy.util.FastArray
- All Implemented Interfaces:
Serializable,Cloneable
Resizable object array optimized for append-heavy internal use and lightweight list views.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FastArrayShared empty instance with zero capacity.intNumber of populated elements in the backing array. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty array with the default initial capacity.FastArray(int initialCapacity) Creates an empty array with the specified initial capacity.Creates an array backed by the supplied object array.Creates an array containing the elements of the supplied collection. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends an element to the end of this array, growing the backing storage when needed.voidAppends the firstsizeelements from the supplied array.voidAppends the contents of the supplied list.voidAppends the populated contents of anotherFastArray.voidclear()Removes all populated elements while preserving the current capacity.clone()Returns a shallow copy with duplicated backing storage.copy()Returns a copy containing the populated elements of this array.get(int index) Returns the element at the specified index.Object[]getArray()Returns the backing storage array.booleanisEmpty()Indicates whether this array contains any populated elements.voidremove(int index) Removes the element at the specified index and compacts the populated range.voidReplaces the element stored at the specified index.intsize()Returns the number of populated elements.toList()Returns a list view of the populated elements.toString()Returns a list-style string containing the populated elements.
-
Field Details
-
EMPTY_LIST
Shared empty instance with zero capacity. -
size
public int sizeNumber of populated elements in the backing array.
-
-
Constructor Details
-
FastArray
public FastArray(int initialCapacity) Creates an empty array with the specified initial capacity.- Parameters:
initialCapacity- the initial storage size
-
FastArray
public FastArray()Creates an empty array with the default initial capacity. -
FastArray
Creates an array containing the elements of the supplied collection.- Parameters:
c- the values to copy
-
FastArray
Creates an array backed by the supplied object array.- Parameters:
objects- the backing storage containing the initial elements
-
-
Method Details
-
get
Returns the element at the specified index.- Parameters:
index- the populated index to read- Returns:
- the stored element
-
add
Appends an element to the end of this array, growing the backing storage when needed.- Parameters:
o- the element to append
-
set
Replaces the element stored at the specified index.- Parameters:
index- the populated index to updateo- the replacement element
-
size
public int size()Returns the number of populated elements.- Returns:
- the logical size of this array
-
clear
public void clear()Removes all populated elements while preserving the current capacity. -
addAll
Appends the populated contents of anotherFastArray.- Parameters:
newData- the source array to append
-
addAll
Appends the firstsizeelements from the supplied array.- Parameters:
newData- the source storagesize- the number of elements to append
-
copy
Returns a copy containing the populated elements of this array.- Returns:
- a new
FastArraywith copied storage
-
isEmpty
public boolean isEmpty()Indicates whether this array contains any populated elements.- Returns:
trueif no elements are stored
-
addAll
Appends the contents of the supplied list.- Parameters:
coll- the values to append
-
remove
public void remove(int index) Removes the element at the specified index and compacts the populated range.- Parameters:
index- the populated index to remove
-
toList
Returns a list view of the populated elements.- Returns:
- a list reflecting the current contents of this array
-
getArray
Returns the backing storage array.- Returns:
- the underlying array, including unused slots
-
toString
Returns a list-style string containing the populated elements. -
clone
Returns a shallow copy with duplicated backing storage.
-