Package org.web3d.vrml.util
Class NodeArray
java.lang.Object
org.web3d.vrml.util.NodeArray
Simple dynamic array structure that holds VRMLNode 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.9 $
- Author:
- Justin Couch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new value to the array.void
Add an array of values in bulk to the array.void
Add an subset of the array of values in bulk to the array.void
Add the contents of the given array to this array.void
clear()
Clear the array so that it contains no valuesget
(int index) Get the value at the given index.int
Find the index of the given node in this list.remove
(int index) Remove the value at the given index.Remove the given value from the array.void
Convenience method to remove the array of values given from this array.void
Set the value at the given index.void
Replace the contents of this list to the values in the given list.int
size()
Get the count of the number of items in the array.VRMLNode[]
toArray()
Turn the values of this array into a real array.VRMLNode[]
Turn the values of this array into a real array by copying them into the given array if possible.
-
Constructor Details
-
NodeArray
public NodeArray()Create a new default array with size 512 items -
NodeArray
public NodeArray(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
-
add
Add the contents of the given array to this array.- Parameters:
nodeList
- The values to be added
-
add
Add an subset of the array of values in bulk to the array. The array should not * be null.- Parameters:
values
- The values to be addedoffset
- The offset into the array to copy overlen
- The number of items to copy
-
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
-
set
Replace the contents of this list to the values in the given list. All current values will be removed.- Parameters:
list
- The list to copy values from
-
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 given value from the array. Uses a very inefficient linear search to locate the object. If the value is not in the array, silently exists with a null return value. If the same object is in the array multiple times, only the first instance is removed.- Parameters:
object
- The value to remove- Returns:
- The value at that index
- Throws:
IndexOutOfBoundsException
- The index was not legal
-
indexOf
Find the index of the given node in this list. If the node is not in the list a value of -1 will be returned. The comparison uses the .equals() to check for equality.- Parameters:
node
- The node instance to look for- Returns:
- The index of the node or -1 if not found
-
remove
Convenience method to remove the array of values given from this array. Any item in the provided array and not in this array is ignored.- Parameters:
nodeList
- The list of objects to remove
-
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
-