Package org.web3d.util
Class ObjectArray
java.lang.Object
org.web3d.util.ObjectArray
Simple dynamic array structure that holds Object instances.
Idea is to save implementation weight when we don't really want to use a full java.util collections class, but don't want to have to re-implement the node copy/paste stuff every time.
- Version:
- $Revision: 1.7 $
- Author:
- Justin Couch
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new default array with size 512 itemsObjectArray
(int initialSize) Create an array with the given initial size -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new value to the array.void
Add an array of values in bulk to the array.void
addAll
(ObjectArray other) Add the values from another ObjectArray in bulk.void
clear()
Clear the array so that it contains no valuesget
(int index) Get the value at the given index.remove
(int index) Remove the value at the given index.Remove the first instance of the object found from this array.void
Set the value at the given index.int
size()
Get the count of the number of items in the array.Object[]
toArray()
Turn the values of this array into a real array.Object[]
Turn the values of this array into a real array by copying them into the given array if possible.
-
Constructor Details
-
ObjectArray
public ObjectArray()Create a new default array with size 512 items -
ObjectArray
public ObjectArray(int initialSize) Create an array with the given initial size- Parameters:
initialSize
- The size to start with
-
-
Method Details
-
size
public int size()Get the count of the number of items in the array.- Returns:
- The number of items in the array
-
clear
public void clear()Clear the array so that it contains no values -
add
Add a new value to the array. Will resize the array if needed to accommodate new values.- Parameters:
newNode
- the value to be added
-
add
Add an array of values in bulk to the array. The array should not be null.- Parameters:
values
- The values to be added
-
addAll
Add the values from another ObjectArray in bulk. The other array cannot be null.- Parameters:
other
- The other ObjectArray
-
get
Get the value at the given index.- Parameters:
index
- The position to get values from- Returns:
- The value at that index
- Throws:
IndexOutOfBoundsException
- The index was not legal
-
set
Set the value at the given index. If the index is out of the range of the current items, it will generate an index exception.- Parameters:
index
- The position to get values fromvalue
- The new value to set- Throws:
IndexOutOfBoundsException
- The index was not legal
-
remove
Remove the value at the given index.- Parameters:
index
- The position to remove the value from- Returns:
- The value at that index
- Throws:
IndexOutOfBoundsException
- The index was not legal
-
remove
Remove the first instance of the object found from this array. The object equivalence is found by first using a == compare and then if that fails, using the .equals() comparison. If this object is in the array multiple times, only the first instance is deleted.- Parameters:
obj
- The object instance to remove- Returns:
- The object removed, if found. Null if not found
-
toArray
Turn the values of this array into a real array. Returns an array with the exact number of items in it. This is a separate copy of the internal array.- Returns:
- The array of values
-
toArray
Turn the values of this array into a real array by copying them into the given array if possible. If the array is big enough then it will copy the values straight in. If not, it will ignore that array and create it's own copy and return that. If the passed array is used, the return value will be a reference to the passed array, otherwise it will be the new copy.- Parameters:
values
- The array to copy values to- Returns:
- The array of values
-