j3d.org Code

org.j3d.util
Class ObjectArray

java.lang.Object
  extended by org.j3d.util.ObjectArray

public class ObjectArray
extends java.lang.Object

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.

Code is sourced from the Xj3D project.

Version:
$Revision: 1.1 $
Author:
Justin Couch

Constructor Summary
ObjectArray()
          Create a new default array with size 512 items
ObjectArray(int initialSize)
          Create an array with the given initial size.
 
Method Summary
 void add(java.lang.Object newNode)
          Add a new value to the array.
 void add(java.lang.Object[] values)
          Add an array of values in bulk to the array.
 void clear()
          Clear the array so that it contains no values
 java.lang.Object get(int index)
          Get the value at the given index.
 java.lang.Object remove(int index)
          Remove the value at the given index.
 java.lang.Object remove(java.lang.Object obj)
          Remove the first instance of the object found from this array.
 void set(int index, java.lang.Object value)
          Set the value at the given index.
 int size()
          Get the count of the number of items in the array.
 java.lang.Object[] toArray()
          Turn the values of this array into a real array.
 java.lang.Object[] toArray(java.lang.Object[] 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

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 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(java.lang.Object 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(java.lang.Object[] values)
Add an array of values in bulk to the array. The array should not be null.

Parameters:
values - The values to be added

get

public java.lang.Object 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,
                java.lang.Object 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

remove

public java.lang.Object 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 java.lang.Object remove(java.lang.Object obj)
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

public java.lang.Object[] 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 java.lang.Object[] toArray(java.lang.Object[] 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

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org