|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.tensegrity.generic.util.ArrayListLong
ArrayListLong 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
ArrayListLong.Iterator and ArrayListLong.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 |
ArrayListLong.Iterator
ArrayListLong.Iterator provides a simple forware iterator with basic versioning. |
class |
ArrayListLong.ListIterator
ArrayListLong.ListIterator is a bidirectional iterator with basic versioning. |
| Constructor Summary | |
ArrayListLong()
Constructs a new arraylist with a default capacity of 8 elements. |
|
ArrayListLong(int initialcapacity)
Constructs a new arraylist with the given initial capacity. |
|
ArrayListLong(int n,
long element)
Constructs a new arraylist and fills it with n copies of the specified element. |
|
ArrayListLong(long[] array)
Constructs a new arraylist and initializes the elements with the contents from the array passed as argument. |
|
| Method Summary | |
void |
add(int index,
long element)
Insert the element into the arraylist at the specified position. |
boolean |
add(long element)
Appends the element at the end of the arraylist. |
boolean |
addAll(ArrayListLong otherlist)
Appends all of the elements of another list after the end of this arraylist. |
int |
binarySearch(long 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(long 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. |
long |
get(int index)
Retrieves the element at the given position in the arraylist. |
int |
indexOf(long element)
Forward search for an element in the arraylist starting at index 0. |
boolean |
isEmpty()
Tests whether this arraylist is empty or not. |
ArrayListLong.Iterator |
iterator()
Returns a simple forward iterator to the caller which can be used to retrieve the contents of the arraylist like this: ArrayListLong.Iterator it = alist.iterator(); while (it.hasNext()) { long l = li.previous (); System.out.println (" : " + l); } For backwards iteration @see ListIterator. |
int |
lastIndexOf(long element)
Seeks an element backwards from the end of the arraylist. |
ArrayListLong.ListIterator |
listIterator()
Returns a simple forward iterator to the caller which can be used to retrieve the contents of the arraylist like this: ArrayListLong.ListIterator it = alist.listIterator(); while (it.hasNext()) { long l = li.next (); System.out.println (" : " + l); } Additionally the list iterator is capable of backwards iteration using the methods @see previous and @see hasPrevious |
ArrayListLong.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: ArrayListLong.ListIterator it = alist.listIterator(alist.size()); while (it.hasPrevious()) { long l = li.previous (); System.out.println (" : " + l); } Additionally the list iterator is capable of backwards iteration using the methods @see previous and @see hasPrevious |
long |
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(long element,
long newElement)
Replaces all occurences of element by newElement. |
void |
reverse()
Reverses the order of the arraylist. |
long |
set(int index,
long 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. |
long[] |
toArray()
Allocates an array whose length is equal to the size() of this arraylist and then copies the contents of the arraylist into it. |
long[] |
toArray(long[] 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 ArrayListLong(int initialcapacity)
initialcapacity - the initial capacity of the array.
InvalidArgumentException - if the initialcapacity
specified is less than 1.public ArrayListLong()
public ArrayListLong(int n,
long element)
n - number of entries to fill with the default elementelement - default elementpublic ArrayListLong(long[] 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(long element)
element - element to look for in the arraylist.
public final int indexOf(long element)
element - element to look for in the arraylist.
public final int lastIndexOf(long element)
element - element to look for in the arraylist.
public final long 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 long set(int index,
long 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(long element)
element - the element to append to the arraylist
true by contract.public final boolean addAll(ArrayListLong otherlist)
otherlist - the list whose elements are to be appended.
public final void add(int index,
long 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 long 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 long[] toArray()
public final long[] toArray(long[] 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(long element)
element - the element to search for
public final boolean replaceAll(long element,
long newElement)
element - the element to replace.newElement - the replacement for the old element.
public final void reverse()
public final ArrayListLong.Iterator iterator()
ArrayListLong.Iterator it = alist.iterator();
while (it.hasNext()) {
long l = li.previous ();
System.out.println (" : " + l);
}
For backwards iteration @see ListIterator.
public final ArrayListLong.ListIterator listIterator()
ArrayListLong.ListIterator it = alist.listIterator();
while (it.hasNext()) {
long 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 ArrayListLong.ListIterator listIterator(int index)
ArrayListLong.ListIterator it = alist.listIterator(alist.size());
while (it.hasPrevious()) {
long 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 | ||||||||||