|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.j3d.util.CircularList
public class CircularList
A circular list (buffer) implementation.
The implementation uses a double linked list. When the toArray method is called, the values are written to the list based on the current position. The code is implemented for speed, not safety. Accessing a single instance from multiple threads is probably going to cause problems. However, it does cache internal entry values amongst instances to save on garbage generation and allocation costs. If the code needs to reduce allocated memory, a convenience method is provided to reduce the internal cache size.
Constructor Summary | |
---|---|
CircularList()
Constructs a new, empty list. |
Method Summary | |
---|---|
void |
add(java.lang.Object o)
Adds the specified element to this list. |
boolean |
addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this set. |
void |
clear()
Removes all of the elements from this set. |
void |
clearCachedObjects()
Clean up the internal cache and reduce it to zero. |
boolean |
contains(java.lang.Object o)
Returns true if this set contains the specified element. |
java.lang.Object |
current()
Get the current item that is being pointed to in the list. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this set for equality. |
int |
hashCode()
Returns the hash code value for this list. |
boolean |
isEmpty()
Check to see if this set contains elements. |
java.lang.Object |
next()
Fetch the next item in the list from this one and advance the current pointer to it. |
java.lang.Object |
previous()
Fetch the previous item in the list from this one and retire the current pointer to it. |
boolean |
remove(java.lang.Object o)
Removes the specified element from this set if it is present. |
boolean |
removeAll(java.util.Collection c)
Removes from this set all of its elements that are contained in the specified collection. |
int |
size()
Returns the number of elements in this set (its cardinality). |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
java.lang.String |
toString()
Returns a string representation of this set. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CircularList()
Method Detail |
---|
public int size()
public boolean isEmpty()
public java.lang.Object next()
public java.lang.Object previous()
public java.lang.Object current()
public boolean contains(java.lang.Object o)
o
- element whose presence in this set is to be tested.
public void add(java.lang.Object o)
o
- element to be added to this set
java.lang.NullPointerException
- The passed object was nullpublic boolean remove(java.lang.Object o)
o
- object to be removed from this set, if present.
public void clear()
public boolean addAll(java.util.Collection c)
This implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.
c
- collection whose elements are to be added to this collection.
java.lang.UnsupportedOperationException
- if this collection does not
support the addAll method.
java.lang.NullPointerException
- if the specified collection is null.public boolean removeAll(java.util.Collection c)
This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.
c
- elements to be removed from this set.
java.lang.UnsupportedOperationException
- if the removeAll method
is not supported by this collection.
java.lang.NullPointerException
- if the specified collection is null.remove(Object)
,
contains(Object)
public java.lang.Object[] toArray()
This implementation allocates the array to be returned, and iterates over the elements in the collection, storing each object reference in the next consecutive element of the array, starting with element 0.
public java.lang.Object[] toArray(java.lang.Object[] array)
If the collection fits in the specified array with room to spare (i.e., the array has more elements than the collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the collection only if the caller knows that the collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
This implementation checks if the array is large enough to contain the collection; if not, it allocates a new array of the correct size and type (using reflection). Then, it iterates over the collection, storing each object reference in the next consecutive element of the array, starting with element 0. If the array is larger than the collection, a null is stored in the first location after the end of the collection.
array
- the array into which the elements of the set are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
java.lang.NullPointerException
- if the specified array is null.
java.lang.ArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in this
collection.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to be compared for equality with this set.
public int hashCode()
This implementation enumerates over the set, calling the hashCode method on each element in the collection, and adding up the results.
hashCode
in class java.lang.Object
public java.lang.String toString()
This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.
toString
in class java.lang.Object
public void clearCachedObjects()
|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |