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