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