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