|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.utility.SortedArrayData<T,T>
messif.utility.SortedCollection<T>
T
- the type of objects stored in this collectionpublic class SortedCollection<T>
Implementation of a sorted collection. The order is maintained using the comparator specified in the constructor. Complexity of insertion is O(log n).
Constructor Summary | |
---|---|
SortedCollection()
Constructs an empty collection. |
|
SortedCollection(java.util.Comparator<? super T> comparator)
Constructs an empty collection. |
|
SortedCollection(int initialCapacity)
Constructs an empty collection with the specified initial capacity. |
|
SortedCollection(int initialCapacity,
java.util.Comparator<? super T> comparator)
Constructs an empty collection with the specified initial capacity. |
|
SortedCollection(int initialCapacity,
int maximalCapacity,
java.util.Comparator<? super T> comparator)
Constructs an empty collection with the specified initial and maximal capacity. |
Method Summary | ||
---|---|---|
boolean |
add(T e)
Adds the specified element to this list. |
|
boolean |
addAll(java.util.Collection<? extends T> c)
Add all of the elements in the specified collection to this list. |
|
void |
clear()
Removes all of the elements from this list. |
|
java.lang.Object |
clone()
Returns a shallow copy of this SortedCollection instance. |
|
protected int |
compare(T key,
T object)
Compares its two arguments for order. |
|
boolean |
contains(java.lang.Object o)
Returns true if this list contains the specified element. |
|
boolean |
containsAll(java.util.Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection. |
|
protected T |
get(int index)
Returns the element at the specified position in this collection. |
|
int |
getMaximalCapacity()
Returns the maximal capatity of this collection. |
|
boolean |
isEmpty()
Returns true if this collection contains no elements. |
|
boolean |
isFull()
Returns true if this collection contains the maximal number of elements. |
|
java.util.Iterator<T> |
iterator()
Returns an iterator over the elements in this collection. |
|
java.util.Iterator<T> |
iterator(int skip,
int count)
Returns an iterator over the elements in this collection skipping the first skip items and returning only count elements. |
|
T |
popLast()
Deprecated. Use removeLast() method instead |
|
protected boolean |
remove(int index)
Removes the element at the specified position in this collection. |
|
boolean |
remove(java.lang.Object o)
Removes the first occurrence of the specified element from this list, if it is present. |
|
boolean |
removeAll(java.util.Collection<?> c)
Removes all of this collection's elements that are also contained in the specified collection. |
|
T |
removeFirst()
Removes and returns the first element of this collection according to the order specified by the comparator. |
|
T |
removeLast()
Removes and returns the last element of this collection according to the order specified by the comparator. |
|
boolean |
retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection. |
|
int |
size()
Returns the number of elements in this collection. |
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list in proper sequence (from first to last element). |
|
|
toArray(E[] array)
Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. |
|
java.lang.String |
toString()
Returns a string representation of this collection. |
Methods inherited from class messif.utility.SortedArrayData |
---|
binarySearch, first, fullSearch, indexOf, last, mergeSort |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
equals, hashCode |
Constructor Detail |
---|
public SortedCollection(int initialCapacity, int maximalCapacity, java.util.Comparator<? super T> comparator) throws java.lang.IllegalArgumentException
initialCapacity
- the initial capacity of the collectionmaximalCapacity
- the maximal capatity of the collectioncomparator
- the comparator that defines ordering
java.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidpublic SortedCollection(int initialCapacity, java.util.Comparator<? super T> comparator) throws java.lang.IllegalArgumentException
initialCapacity
- the initial capacity of the collectioncomparator
- the comparator that defines ordering
java.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidpublic SortedCollection(java.util.Comparator<? super T> comparator) throws java.lang.IllegalArgumentException
comparator
- the comparator that defines ordering
java.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidpublic SortedCollection(int initialCapacity) throws java.lang.IllegalArgumentException
initialCapacity
- the initial capacity of the collection
java.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidpublic SortedCollection() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidMethod Detail |
---|
protected int compare(T key, T object) throws java.lang.ClassCastException
SortedArrayData
compare
in class SortedArrayData<T,T>
key
- the key to indexCompareobject
- the object to be compared
java.lang.ClassCastException
- if the arguments' types prevent them from
being compared by this comparator.public int size()
size
in interface java.util.Collection<T>
size
in class SortedArrayData<T,T>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<T>
public boolean isFull()
public int getMaximalCapacity()
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<T>
o
- element whose presence in this list is to be tested
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<T>
c
- collection to be checked for containment in this collection
java.lang.NullPointerException
- if the specified collection is nullcontains(Object)
protected final T get(int index)
get
in class SortedArrayData<T,T>
index
- index of the element to return
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public T removeLast() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if the collection is empty@Deprecated public T popLast() throws java.util.NoSuchElementException
removeLast()
method instead
java.util.NoSuchElementException
- if the collection is emptypublic T removeFirst() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if the collection is emptypublic java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public java.lang.Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in interface java.util.Collection<T>
public <E> E[] toArray(E[] array)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
toArray
in interface java.util.Collection<T>
E
- the type of array componentsarray
- the array into which the elements of the list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
java.lang.ArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in
this list
java.lang.NullPointerException
- if the specified array is nullpublic boolean add(T e)
add
in interface java.util.Collection<T>
e
- element to be appended to this list
Collection.add(E)
)public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<T>
o
- element to be removed from this list, if present
protected boolean remove(int index)
index
- index of the element to remove
public boolean addAll(java.util.Collection<? extends T> c)
addAll
in interface java.util.Collection<T>
c
- collection containing elements to be added to this list
java.lang.NullPointerException
- if the specified collection is nullpublic boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<T>
c
- collection containing elements to be removed from this collection
java.lang.NullPointerException
- if the specified collection is nullremove(Object)
,
contains(Object)
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<T>
c
- collection containing elements to be retained in this collection
java.lang.NullPointerException
- if the specified collection is nullremove(Object)
,
contains(Object)
public void clear()
clear
in interface java.util.Collection<T>
public java.lang.String toString()
String.valueOf(Object)
.
toString
in class java.lang.Object
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
iterator
in interface java.util.Collection<T>
public java.util.Iterator<T> iterator(int skip, int count)
skip
items and returning only count
elements. If count
is less than or equal to zero, all objects from the collection (except for
skip
) are returned. Note that their order is defined by the comparator.
skip
- number of items to skipcount
- number of items to iterate (maximally, can be less)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |