Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.util
Class NodeArray

java.lang.Object
  extended by org.web3d.vrml.util.NodeArray

public class NodeArray
extends java.lang.Object

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.8 $
Author:
Justin Couch

Constructor Summary
NodeArray()
          Create a new default array with size 512 items
NodeArray(int initialSize)
          Create an array with the given initial size
 
Method Summary
 void add(NodeArray nodeList)
          Add the contents of the given array to this array.
 void add(VRMLNode newNode)
          Add a new value to the array.
 void add(VRMLNode[] values)
          Add an array of values in bulk to the array.
 void add(VRMLNode[] values, int offset, int len)
          Add an subset of the array of values in bulk to the array.
 void clear()
          Clear the array so that it contains no values
 VRMLNode get(int index)
          Get the value at the given index.
 int indexOf(VRMLNode node)
          Find the index of the given node in this list.
 VRMLNode remove(int index)
          Remove the value at the given index.
 void remove(NodeArray nodeList)
          Convenience method to remove the array of values given from this array.
 VRMLNode remove(VRMLNode object)
          Remove the given value from the array.
 void set(int index, VRMLNode value)
          Set the value at the given index.
 void set(NodeArray list)
          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[] toArray(VRMLNode[] values)
          Turn the values of this array into a real array by copying them into the given array if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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

public void add(VRMLNode newNode)
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

public void add(VRMLNode[] values)
Add an array of values in bulk to the array. The array should not be null.

Parameters:
values - The values to be added

add

public void add(NodeArray nodeList)
Add the contents of the given array to this array.

Parameters:
nodeList - The values to be added

add

public void add(VRMLNode[] values,
                int offset,
                int len)
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 added
offset - The offset into the array to copy over
len - The number of items to copy

get

public VRMLNode get(int index)
Get the value at the given index.

Parameters:
index - The position to get values from
Returns:
The value at that index
Throws:
java.lang.IndexOutOfBoundsException - The index was not legal

set

public void set(int index,
                VRMLNode value)
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 from
value - The new value to set
Throws:
java.lang.IndexOutOfBoundsException - The index was not legal

set

public void set(NodeArray list)
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

public VRMLNode remove(int index)
Remove the value at the given index.

Parameters:
index - The position to remove the value from
Returns:
The value at that index
Throws:
java.lang.IndexOutOfBoundsException - The index was not legal

remove

public VRMLNode remove(VRMLNode object)
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:
java.lang.IndexOutOfBoundsException - The index was not legal

indexOf

public int indexOf(VRMLNode node)
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

public void remove(NodeArray nodeList)
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

public VRMLNode[] 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

public VRMLNode[] toArray(VRMLNode[] values)
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

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium