|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList
edu.northwestern.at.utils.SortedArrayList
public class SortedArrayList
Sorted array list.
This class extends ArrayList to support sorted lists.
All elements of the list should implement the Comparable interface, or you may supply a custom Comparator instead. If the objects do not support comparable and you do not supply a custom Comparator, the result of the toString() function for each object is used.
The ArrayList methods for adding or settings elements at specific indices are not supported raise an UnsupportedOperationException if used.
Field Summary | |
---|---|
protected java.util.Comparator |
comparator
Optional Comparator used for comparing objects in the list. |
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
SortedArrayList()
Create empty sorted array list. |
|
SortedArrayList(java.util.Collection collection)
Create sorted array list from a collection. |
|
SortedArrayList(java.util.Collection collection,
java.util.Comparator comparator)
Create sorted array list from a collection with specified comparator. |
|
SortedArrayList(java.util.Comparator comparator)
Create empty sorted array list with specified Comparator. |
|
SortedArrayList(int initialCapacity)
Create empty sorted array list with specified initial capacity. |
|
SortedArrayList(int initialCapacity,
java.util.Comparator comparator)
Create empty sorted array list with specified initial capacity and comparator. |
|
SortedArrayList(java.lang.Object[] array)
Create sorted array list from an array. |
|
SortedArrayList(java.lang.Object[] array,
java.util.Comparator comparator)
Create sorted array list from an array with specified comparator. |
Method Summary | |
---|---|
void |
add(int index,
java.lang.Object object)
Add element at specified index. |
boolean |
add(java.lang.Object object)
Add an object to the list. |
boolean |
addAll(java.util.Collection collection)
Add all elements of a collection. |
boolean |
addAll(int index,
java.util.Collection collection)
Add all elements of a collection at a specified index. |
boolean |
addAll(java.lang.Object[] array)
Add all elements of an array. |
protected int |
compare(java.lang.Object object1,
java.lang.Object object2)
Compares two elements. |
boolean |
contains(java.lang.Object object)
Determine if list contains a specified value. |
int |
indexOf(java.lang.Object object)
Return index of first matching list entry. |
int |
lastIndexOf(java.lang.Object object)
Return index of last matching list entry. |
java.lang.Object |
set(int index,
java.lang.Object object)
Set specified element of list. |
void |
setComparator(java.util.Comparator comparator)
Set comparator for list elements. |
Methods inherited from class java.util.ArrayList |
---|
clear, clone, ensureCapacity, get, isEmpty, remove, remove, removeRange, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
---|
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, removeAll, retainAll, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList |
Field Detail |
---|
protected java.util.Comparator comparator
Constructor Detail |
---|
public SortedArrayList()
public SortedArrayList(int initialCapacity)
public SortedArrayList(java.util.Collection collection)
collection
- The source collection. public SortedArrayList(java.lang.Object[] array)
array
- The source array. public SortedArrayList(java.util.Comparator comparator)
public SortedArrayList(java.util.Collection collection, java.util.Comparator comparator)
collection
- The source collection.comparator
- The comparator. public SortedArrayList(java.lang.Object[] array, java.util.Comparator comparator)
array
- The source array.comparator
- The comparator. public SortedArrayList(int initialCapacity, java.util.Comparator comparator)
Method Detail |
---|
public void setComparator(java.util.Comparator comparator)
comparator
- The comparator. public boolean add(java.lang.Object object)
add
in interface java.util.Collection
add
in interface java.util.List
add
in class java.util.ArrayList
object
- Object to add.
public void add(int index, java.lang.Object object)
add
in interface java.util.List
add
in class java.util.ArrayList
public boolean addAll(java.util.Collection collection)
addAll
in interface java.util.Collection
addAll
in interface java.util.List
addAll
in class java.util.ArrayList
collection
- The source collection.
public boolean addAll(java.lang.Object[] array)
array
- The source array.
public boolean addAll(int index, java.util.Collection collection)
addAll
in interface java.util.List
addAll
in class java.util.ArrayList
public boolean contains(java.lang.Object object)
contains
in interface java.util.Collection
contains
in interface java.util.List
contains
in class java.util.ArrayList
object
- The object (value) to find.
public int indexOf(java.lang.Object object)
indexOf
in interface java.util.List
indexOf
in class java.util.ArrayList
object
- The object to find.
public int lastIndexOf(java.lang.Object object)
lastIndexOf
in interface java.util.List
lastIndexOf
in class java.util.ArrayList
object
- The object to find.
public java.lang.Object set(int index, java.lang.Object object)
set
in interface java.util.List
set
in class java.util.ArrayList
protected int compare(java.lang.Object object1, java.lang.Object object2)
object1
- First object.object2
- Second object.
Assumes the two objects are not null, since null objects cannot added to the list. If no comparator is defined for this SortedArrayList, and one or both of the objects are not comparable, a case-ignoring comparison is performed on the "toString()" values for each object.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |