|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjaggregate.AbstractCollection<E>
jaggregate.AbstractExtensibleCollection<E>
jaggregate.SortedCollection<E>
E - A restriction on the types of elements that may be included in the
collectionpublic class SortedCollection<E>
Represents a variable-sized collection of objects whose elements are ordered based on a sort order. The sort order is specified by a comparator. Elements may be added, removed, or inserted, and can be accessed using external integer keys.
| Constructor Summary | |
|---|---|
SortedCollection(Comparator<? super E> comparator)
Creates an empty sorted collection whose elements are sorted using the given comparator. |
|
SortedCollection(Comparator<? super E> comparator,
Collection<? extends E> newElements)
Creates a sorted collection whose elements are sorted using the given comparator, and containing the elements of the given collection. |
|
SortedCollection(Comparator<? super E> comparator,
E... newElements)
Creates a sorted collection whose elements are sorted using the given comparator, and containing the elements of the given array. |
|
SortedCollection(Comparator<? super E> comparator,
Iterable<? extends E> newElements)
Creates a sorted collection whose elements are sorted using the given comparator, and containing the elements of the given iterable. |
|
| Method Summary | ||
|---|---|---|
void |
add(E newElement)
Adds a new element to this collection. |
|
E |
after(E target)
Answers the object immediately following the first element which is equivalent to the given target in this sequence. |
|
E |
at(int index)
Answers the element at the given position in this sequence. |
|
E |
before(E target)
Answers the object immediately preceding the first element which is equivalent to the given target in this sequence. |
|
|
collect(UnaryFunctor<? super E,? extends R> transformer)
Evaluates the given transformer for each element of this collection, with the element as the parameter, and answers a new collection containing the results of these evaluations. The elements are traversed in the order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. |
|
Comparator<? super E> |
comparator()
Answers the comparator which is used to order this collection's elements. |
|
SortedCollection<E> |
concat(ReadOnlySequence<? extends E> otherSequence)
Answers a new sequence containing all of this sequence's elements in their original order followed by all of the elements of the given sequence, in their original order. Since this collection sorts its elements, the result will also be sorted as defined by this collection's comparator. |
|
SortedCollection<E> |
copyRange(int start,
int stop)
Answers a new sequence containing the specified range of elements of this sequence in their original order. |
|
SortedCollection<E> |
copyWith(E newElement)
Answers a new sequence with size one greater than the size of this sequence, containing the elements of this sequence and a given new element placed at the end. |
|
SortedCollection<E> |
copyWithout(E oldElement)
Answers a new sequence with all of the elements of this sequence that are not equivalent to the given element, in their original order. |
|
void |
doWithIndex(BinaryFunctor<? super Integer,? super E,?> operation)
Evaluates the given operation with the index of each element of this sequence, in order, together with the element itself. |
|
|
doWithOthers(ReadOnlySequence<? extends T> otherSequence,
BinaryFunctor<? super E,? super T,?> operation)
For each element of this sequence and the corresponding element of the given sequence, evaluates the given operation with this sequence's element as the first parameter, and the element of the other sequence as the second parameter. |
|
static
|
emptySortedCollection(Comparator<? super T> comparator)
Creates an empty sorted collection whose elements are sorted using the given comparator. |
|
boolean |
equals(Object that)
|
|
int |
findFirst(UnaryCondition<? super E> discriminator)
Answers the index of the first element which causes the given discriminator to answer true when the element is used as a parameter. |
|
int |
findLast(UnaryCondition<? super E> discriminator)
Answers the index of the last element which causes the given discriminator to answer true when the element is used as a parameter. |
|
E |
first()
Answers the element at index 0 in this sequence. |
|
void |
forEachDo(UnaryFunctor<? super E,?> operation)
For each element of this collection, evaluates the given operation with the element as the parameter. |
|
void |
forEachInRangeDo(int start,
int stop,
UnaryFunctor<? super E,?> operation)
For those elements of this sequence between two given positions, inclusive, evaluates the given operation with the element at that index as its argument. |
|
void |
forEachInRangeDoWithIndex(int start,
int stop,
BinaryFunctor<? super Integer,? super E,?> operation)
For those elements of this sequence between two given positions, inclusive, evaluates the given operation with an element of this sequence as the first argument and the element's position (index) as the second. |
|
void |
forEachInReverseDo(UnaryFunctor<? super E,?> operation)
Evaluates the given operation with each element of this sequence in the reverse of this sequence's standard traversal order. |
|
int |
hashCode()
|
|
int |
indexOf(E target)
Answers the index of the first element which is equivalent to the given target}. |
|
int |
indexOf(ReadOnlySequence<? extends E> targetSequence,
int start)
Answers the index of the first element of this sequence which is the start of a subsequence which matches a given target sequence. |
|
E |
last()
Answers the last element of this sequence, the element at the index equal to this sequence's size minus 1. |
|
SortedCollection<E> |
reject(UnaryCondition<? super E> discriminator)
Answers a new collection which contains only the elements in this collection which cause the given discriminator to answer false.
For each element of this collection, discriminator is evaluated with the
element as the parameter. Each element which causes discriminator to
answer false is included in the new collection.
The elements are traversed in the order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection. |
|
boolean |
remove(E oldElement)
Removes the first element of this collection which is equivalent to the given element. |
|
E |
removeAt(int index)
Removes and answers the element at a given position in this sequence. |
|
E |
removeFirst()
Removes and answers the first element of this sequence. |
|
boolean |
removeIf(UnaryCondition<? super E> discriminator)
Removes each element of this collection which causes the given discriminator to answer true.
The elements are tested in the same order in which they would be enumerated by
forEachDo for this collection. |
|
E |
removeLast()
Removes and answers the last element of this sequence. |
|
boolean |
retainIf(UnaryCondition<? super E> discriminator)
Removes each element of this collection which causes the given discriminator to answer false.
The elements are tested in the same order in which they would be enumerated by
forEachDo for this collection. |
|
ReadOnlySequence<E> |
reverse()
Answers a sequence with the elements of this sequence arranged in reverse order. |
|
SortedCollection<E> |
select(UnaryCondition<? super E> discriminator)
Answers a new collection which contains only the elements in this collection which cause the given discriminator to answer true.
For each element of this collection, discriminator is evaluated with the
element as the parameter. Each element which causes discriminator to
answer true is included in the new collection.
The elements are traversed in order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection. |
|
int |
size()
Answers the number of elements in this collection. |
|
static
|
sortedCollectionFrom(Comparator<? super T> comparator,
Collection<? extends T> newElements)
Creates a sorted collection whose elements are sorted using the given comparator, and containing the elements of the given collection. |
|
static
|
sortedCollectionFrom(Comparator<? super T> comparator,
Iterable<? extends T> newElements)
Creates a sorted collection whose elements are sorted using the given comparator, and containing the elements of the given iterable. |
|
static
|
sortedCollectionWith(Comparator<? super T> comparator,
T... newElements)
Creates a sorted collection whose elements are sorted using the given comparator, and containing the elements of the given array. |
|
SortedCollection<E> |
toSortedCollection()
Answers a sorted collection with the same elements as this collection. If this collection has established an ordering on its elements, then that ordering is used in the answer. Otherwise, order of the elements is arbitrary--in such a case, one should probably use the overload of this method that accepts a comparator. Answers self. |
|
String |
toString()
|
|
| Methods inherited from class jaggregate.AbstractExtensibleCollection |
|---|
addAll, addAll, addAll, addAll, removeAll, removeAll, removeAll, removeAll, retainAll, retainAll, retainAll, retainAll |
| Methods inherited from class jaggregate.AbstractCollection |
|---|
allSatisfy, anySatisfy, detect, includes, inject, isEmpty, occurrencesOf, rehash, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface jaggregate.Collection |
|---|
allSatisfy, anySatisfy, detect, includes, inject, isEmpty, occurrencesOf, rehash, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection |
| Methods inherited from interface jaggregate.Collection |
|---|
allSatisfy, anySatisfy, detect, includes, inject, isEmpty, occurrencesOf, rehash, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection |
| Constructor Detail |
|---|
public SortedCollection(Comparator<? super E> comparator)
comparator - the comparator with which to compare elements for sorting
NullPointerException - if comparator is null
public SortedCollection(Comparator<? super E> comparator,
Collection<? extends E> newElements)
comparator - the comparator with which to compare elements for sortingnewElements - the elements to add to the new collection
NullPointerException - if either comparator or newElements
is null
public SortedCollection(Comparator<? super E> comparator,
E... newElements)
comparator - the comparator with which to compare elements for sortingnewElements - the elements to add to the new collection
NullPointerException - if either comparator or newElements
is null
public SortedCollection(Comparator<? super E> comparator,
Iterable<? extends E> newElements)
comparator - the comparator with which to compare elements for sortingnewElements - the elements to add to the new collection
NullPointerException - if either comparator or newElements
is null| Method Detail |
|---|
public static <T> SortedCollection<T> emptySortedCollection(Comparator<? super T> comparator)
T - the type of elements allowed in the new sorted collectioncomparator - the comparator with which to compare elements for sorting
NullPointerException - if comparator is null
public static <T> SortedCollection<T> sortedCollectionFrom(Comparator<? super T> comparator,
Collection<? extends T> newElements)
T - the type of elements allowed in the new sorted collectioncomparator - the comparator with which to compare elements for sortingnewElements - the elements to add to the new collection
NullPointerException - if either comparator or newElements
is null
public static <T> SortedCollection<T> sortedCollectionWith(Comparator<? super T> comparator,
T... newElements)
T - the type of elements allowed in the new sorted collectioncomparator - the comparator with which to compare elements for sortingnewElements - the elements to add to the new collection
NullPointerException - if either comparator or newElements
is null
public static <T> SortedCollection<T> sortedCollectionFrom(Comparator<? super T> comparator,
Iterable<? extends T> newElements)
T - the type of elements allowed in the new sorted collectioncomparator - the comparator with which to compare elements for sortingnewElements - the elements to add to the new collection
NullPointerException - if either comparator or newElements
is nullpublic SortedCollection<E> toSortedCollection()
toSortedCollection in interface Collection<E>toSortedCollection in class AbstractCollection<E>public <R> OrderedCollection<R> collect(UnaryFunctor<? super E,? extends R> transformer)
forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection.
collect in interface Collection<E>collect in interface ContractibleSequence<E>collect in interface ExtensibleCollection<E>collect in interface ReadOnlySequence<E>collect in class AbstractExtensibleCollection<E>R - return type of the transformertransformer - the transformer to evaluate
public void forEachDo(UnaryFunctor<? super E,?> operation)
forEachDo in interface Collection<E>forEachDo in interface ReadOnlySequence<E>operation - the operation to performpublic SortedCollection<E> reject(UnaryCondition<? super E> discriminator)
false.
For each element of this collection, discriminator is evaluated with the
element as the parameter. Each element which causes discriminator to
answer false is included in the new collection.
The elements are traversed in the order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection.
reject in interface Collection<E>reject in interface ContractibleSequence<E>reject in interface ExtensibleCollection<E>reject in interface ReadOnlySequence<E>reject in class AbstractExtensibleCollection<E>discriminator - the discriminator to evaluate
public SortedCollection<E> select(UnaryCondition<? super E> discriminator)
true.
For each element of this collection, discriminator is evaluated with the
element as the parameter. Each element which causes discriminator to
answer true is included in the new collection.
The elements are traversed in order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection.
select in interface Collection<E>select in interface ContractibleSequence<E>select in interface ExtensibleCollection<E>select in interface ReadOnlySequence<E>select in class AbstractExtensibleCollection<E>discriminator - the discriminator to evaluate
public int size()
size in interface Collection<E>public SortedCollection<E> concat(ReadOnlySequence<? extends E> otherSequence)
otherSequence.
Sequences that enforce an ordering on their elements are permitted to refine
this message to reorder the result.
Since this collection sorts its elements, the result will also be sorted
as defined by this collection's comparator.
concat in interface ReadOnlySequence<E>otherSequence -
otherSequencepublic E after(E target)
target
is the traversal order defined by forEachDo for
this sequence.
after in interface ReadOnlySequence<E>target - the object to lookup
targetpublic E at(int index)
at in interface ReadOnlySequence<E>index - the index to lookup
public E before(E target)
before in interface ReadOnlySequence<E>target - the object to lookup
target
public SortedCollection<E> copyRange(int start,
int stop)
start in this
sequence is at index 0 in the new sequence; the element at
start + 1 is at index 1, etc. If stop < start, then the
new sequence is empty. Otherwise, the size of the new sequence is max(0, stop - start).
The given indices must be non-negative.
copyRange in interface ReadOnlySequence<E>start - the beginning indexstop - the ending index
public SortedCollection<E> copyWith(E newElement)
copyWith in interface ReadOnlySequence<E>newElement - element to add to the copy
newElement appendedpublic SortedCollection<E> copyWithout(E oldElement)
copyWithout in interface ReadOnlySequence<E>oldElement - the element to strip from the copy of this sequence
oldElement removedpublic int findFirst(UnaryCondition<? super E> discriminator)
true when the element is used as a parameter. Answers -1
if no such element is found.
The elements are traversed in the order specified by forEachDo for this sequence.
findFirst in interface ReadOnlySequence<E>discriminator - the discriminator to evaluate
-1 if there is no matchpublic int findLast(UnaryCondition<? super E> discriminator)
true when the element is used as a parameter. Answers -1
if no such element is found.
The elements are traversed in the order specified by forEachInReverseDo for this sequence.
findLast in interface ReadOnlySequence<E>discriminator - the discriminator to evaluate
-1 if there is no matchpublic void forEachInReverseDo(UnaryFunctor<? super E,?> operation)
forEachDo. Each element
is visited exactly once.
forEachInReverseDo in interface ReadOnlySequence<E>operation - the operation to evaluatepublic E first()
0 in this sequence.
first in interface ReadOnlySequence<E>
public void forEachInRangeDo(int start,
int stop,
UnaryFunctor<? super E,?> operation)
forEachInRangeDo in interface ReadOnlySequence<E>start - beginning indexstop - ending indexoperation - the operation to evaluate
public void forEachInRangeDoWithIndex(int start,
int stop,
BinaryFunctor<? super Integer,? super E,?> operation)
forEachInRangeDoWithIndex in interface ReadOnlySequence<E>start - beginning indexstop - ending indexoperation - the operation to evaluatepublic int indexOf(E target)
-1 if no such element is found.
The elements are traversed in the order specified by forEachDo for this sequence.
indexOf in interface ReadOnlySequence<E>target - element to match
-1 if no match
public int indexOf(ReadOnlySequence<? extends E> targetSequence,
int start)
start is checked for
a match with targetSequence. To match, each element of a subsequence of
this sequence must be equivalent to the corresponding element of\
targetSequence. Answers the index of the first element which begins a
matching subsequence; no further subsequences are considered.
Answers -1 if no such subsequence is found in this sequence, or if
targetSequence is empty.
The elements are traversed in the order specified by forEachDo message for this sequence.
indexOf in interface ReadOnlySequence<E>targetSequence - sequence to matchstart - index at which to begin the search
-1 if nonepublic void doWithIndex(BinaryFunctor<? super Integer,? super E,?> operation)
operation is evaluated with the index of each element of this sequence as
the first argument and the element itself as the second argument. Evaluation is
in indexed order starting at 0. The first element is at index 0,
the second at index 1, etc. The index of the last element is equal to
this sequence's size minus 1.
doWithIndex in interface ReadOnlySequence<E>operation - the operation to performpublic E last()
last in interface ReadOnlySequence<E>public ReadOnlySequence<E> reverse()
forEachInReverseDo message,
adding each element of this sequence to the new sequence.
reverse in interface ReadOnlySequence<E>
public <T> void doWithOthers(ReadOnlySequence<? extends T> otherSequence,
BinaryFunctor<? super E,? super T,?> operation)
otherSequence must have the same size.
The elements of this sequence and otherSequence are traversed in indexed
order starting at 0. The operation is evaluated with the
elements at index 0 in the two sequences, then index 1, etc.
doWithOthers in interface ReadOnlySequence<E>T - a constraint on the types of elements in the given sequenceotherSequence - the other elements to use in the evaluationoperation - the operation to performpublic void add(E newElement)
newElement in the element traversal order is unspecified.
Conformant protocols may place restrictions on the characteristics of objects
that are valid elements. Unless otherwise specified, any object that is of the
same class as or of a subclass of this collection's type parameter is acceptable.
add in interface ExtensibleCollection<E>newElement - the element to addpublic boolean remove(E oldElement)
forEachDo for this collection.
remove in interface ExtensibleCollection<E>oldElement - the element to remove
true if any removal occurredpublic E removeAt(int index)
removeAt in interface ContractibleSequence<E>index - the index at which to remove the element
public E removeFirst()
removeFirst in interface ContractibleSequence<E>public E removeLast()
removeLast in interface ContractibleSequence<E>public boolean removeIf(UnaryCondition<? super E> discriminator)
true.
The elements are tested in the same order in which they would be enumerated by
forEachDo for this collection.
removeIf in interface ExtensibleCollection<E>removeIf in class AbstractExtensibleCollection<E>discriminator - the discriminator to evaluate
true if any removal occurredpublic boolean retainIf(UnaryCondition<? super E> discriminator)
false.
The elements are tested in the same order in which they would be enumerated by
forEachDo for this collection.
retainIf in interface ExtensibleCollection<E>retainIf in class AbstractExtensibleCollection<E>discriminator - the discriminator to evaluate
true if any removal occurredpublic Comparator<? super E> comparator()
public boolean equals(Object that)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||