|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.tensegrity.generic.util.ArrayListFloat
ArrayListFloat implements a java.util.List alike container
for efficient storing of a single primitive java-type, avoiding
the overhead of storing wrapper objects. The interfaces Collection
and List are not implemented intentionally, since this class doesn't
work with subtypes of Object. Nevertheless the method signatures and
the semantics are the same. An advantage of not implementing the interface
is that we don't have to use virtual invocation and can declare methods
as final, which gives us superior performance.
Things not implemented that can be found in the standard ArrayList include:
public ArrayList(Collection);
In addition to the above methods, the provided
ArrayListFloat.Iterator and ArrayListFloat.ListIterator do not
have a remove() method. You can use the container
structure itself in case you need to remove elements.
The iterators will throw the runtime-exception
ListModifiedException in case they detect themselves
that they were modified since the iterator was instanciated. This is
NOT RELIABLE in the context of a multithreaded
application. Only proper synchronization provides memory-barriers in
the java programming language. Thus this is merely a helpful technique
that might detect errors in concurrent programming. Only in a serialized
programming context, the programmer can rely on the exception being
generated each time the array is illegaly modified.
| Nested Class Summary | |
class |
ArrayListFloat.Iterator
ArrayListFloat.Iterator provides a simple forware iterator with basic versioning. |
class |
ArrayListFloat.ListIterator
ArrayListFloat.ListIterator is a bidirectional iterator with basic versioning. |
| Constructor Summary | |
ArrayListFloat()
Constructs a new arraylist with a default capacity of 8 elements. |
|
ArrayListFloat(float[] array)
Constructs a new arraylist and initializes the elements with the contents from the array passed as argument. |
|
ArrayListFloat(int initialcapacity)
Constructs a new arraylist with the given initial capacity. |
|
ArrayListFloat(int n,
float element)
Constructs a new arraylist and fills it with n copies of the specified element. |
|
| Method Summary | |
boolean |
add(float element)
Appends the element at the end of the arraylist. |
void |
add(int index,
float element)
Insert the element into the arraylist at the specified position. |
boolean |
addAll(ArrayListFloat otherlist)
Appends all of the elements of another list after the end of this arraylist. |
int |
binarySearch(float element)
Performs a binary search on the array. |
void |
clear()
Removes all elements from the arraylist. |
java.lang.Object |
clone()
Makes a shallow copy of arraylist. |
boolean |
contains(float element)
Checks whether an element is contained in the arraylist. |
void |
ensureCapacity(int newcapacity)
Restructure this arraylist so that its internal capacity is equal or larger than the passed argument. |
float |
get(int index)
Retrieves the element at the given position in the arraylist. |
int |
indexOf(float element)
Forward search for an element in the arraylist starting at index 0. |
boolean |
isEmpty()
Tests whether this arraylist is empty or not. |
ArrayListFloat.Iterator |
iterator()
Returns a simple forward iterator to the caller which can be used to retrieve the contents of the arraylist like this: ArrayListFloat.Iterator it = alist.iterator(); while (it.hasNext()) { float l = li.previous (); System.out.println (" : " + l); } For backwards iteration @see ListIterator. |
int |
lastIndexOf(float element)
Seeks an element backwards from the end of the arraylist. |
ArrayListFloat.ListIterator |
listIterator()
Returns a simple forward iterator to the caller which can be used to retrieve the contents of the arraylist like this: ArrayListFloat.ListIterator it = alist.listIterator(); while (it.hasNext()) { float l = li.next (); System.out.println (" : " + l); } Additionally the list iterator is capable of backwards iteration using the methods @see previous and @see hasPrevious |
ArrayListFloat.ListIterator |
listIterator(int index)
Returns a simple forward iterator with user-specified starting position which can be used to retrieve the contents of the arraylist in reverse order like this: ArrayListFloat.ListIterator it = alist.listIterator(alist.size()); while (it.hasPrevious()) { float l = li.previous (); System.out.println (" : " + l); } Additionally the list iterator is capable of backwards iteration using the methods @see previous and @see hasPrevious |
float |
remove(int index)
Removes the element at the specified position. |
void |
removeRange(int from,
int to)
Removes the elements whose index is between from (inclusive) and to(exclusive). |
boolean |
replaceAll(float element,
float newElement)
Replaces all occurences of element by newElement. |
void |
reverse()
Reverses the order of the arraylist. |
float |
set(int index,
float element)
Sets the element at the given position in the arraylist. |
int |
size()
Queries the size of this arraylist. |
void |
sort()
Sorts the array in ascending order using quicksort. |
void |
sort(boolean descending)
Sorts the array in ascending or descending order using quicksort. |
float[] |
toArray()
Allocates an array whose length is equal to the size() of this arraylist and then copies the contents of the arraylist into it. |
float[] |
toArray(float[] dest)
This copies the elements from this array to the passed array-reference. |
java.lang.String |
toString()
Returns a string-representation of the array. |
void |
trimToSize()
Trims this array's capacity to its actual size. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ArrayListFloat(int initialcapacity)
initialcapacity - the initial capacity of the array.
InvalidArgumentException - if the initialcapacity
specified is less than 1.public ArrayListFloat()
public ArrayListFloat(int n,
float element)
n - number of entries to fill with the default elementelement - default elementpublic ArrayListFloat(float[] array)
array - the array from which the arraylist is initialized.| Method Detail |
public final void trimToSize()
public final void ensureCapacity(int newcapacity)
newcapacity - the new capacity of the arraylist.
Specifying a negative cacacity will cause this method to have
no effect.public final int size()
public final boolean isEmpty()
public final boolean contains(float element)
element - element to look for in the arraylist.
public final int indexOf(float element)
element - element to look for in the arraylist.
public final int lastIndexOf(float element)
element - element to look for in the arraylist.
public final float get(int index)
index - the index of the element that should be returned.
InvalidArgumentException - thrown if
the argument points to an illegal index less than 0 or
equal-or-greater than the current size of the arraylist.
public final float set(int index,
float element)
index - the index of the element that should be returned.element - the element to set at the specified position
IllegalElementException - thrown if
the argument points to an illegal index less than 0 or
equal-or-greater than the current size of the arraylist.public final boolean add(float element)
element - the element to append to the arraylist
true by contract.public final boolean addAll(ArrayListFloat otherlist)
otherlist - the list whose elements are to be appended.
public final void add(int index,
float element)
index - the index where to insert.element - the element to insert into the arraylist
IllegalElementException - thrown if
the argument points to an illegal index less than 0 or
greater than the current size of the arraylist.
public final void removeRange(int from,
int to)
from must be less than to
with one exception: if from is equal to to
then the method has no effect.
from - starting point for removal (inclusive)to - end point for removal (exclusive)public final float remove(int index)
index - position of the element that should be removed.
IllegalElementException - thrown if the index is not pointing to an element in
the arraylist.public final void clear()
public java.lang.Object clone()
public final float[] toArray()
public final float[] toArray(float[] dest)
dest - the array to copy the contents into if possible.
public java.lang.String toString()
public final void sort()
public final void sort(boolean descending)
descending - flag that determines the sorting order. If set to
true, then the sorting will be done in descending order.public final int binarySearch(float element)
element - the element to search for
public final boolean replaceAll(float element,
float newElement)
element - the element to replace.newElement - the replacement for the old element.
public final void reverse()
public final ArrayListFloat.Iterator iterator()
ArrayListFloat.Iterator it = alist.iterator();
while (it.hasNext()) {
float l = li.previous ();
System.out.println (" : " + l);
}
For backwards iteration @see ListIterator.
public final ArrayListFloat.ListIterator listIterator()
ArrayListFloat.ListIterator it = alist.listIterator();
while (it.hasNext()) {
float l = li.next ();
System.out.println (" : " + l);
}
Additionally the list iterator is capable of backwards iteration
using the methods @see previous and @see hasPrevious
public final ArrayListFloat.ListIterator listIterator(int index)
ArrayListFloat.ListIterator it = alist.listIterator(alist.size());
while (it.hasPrevious()) {
float l = li.previous ();
System.out.println (" : " + l);
}
Additionally the list iterator is capable of backwards iteration
using the methods @see previous and @see hasPrevious
index - the initial position of the iterator.
IllegalElementException - thrown if the index is not pointing to an element in
the arraylist.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||