|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.molae.pipe.basic.ObjectProxy<B> net.sf.molae.pipe.basic.CollectionProxy<B,E> net.sf.molae.pipe.basic.CollectionAsSet<B,E> net.sf.molae.pipe.sorted.SetAsSortedSet<B,E>
public class SetAsSortedSet<B extends Collection<E>,E>
If it can be guaranteed that a collection is a set and that its
iterator returns elements in sorted order,
this wrapper can be used to create a SortedSet
implementation.
Constructor Summary | |
---|---|
|
SetAsSortedSet(B base,
Comparator<? super E> comparator)
Constructs a SetAsSortedSet object. |
protected |
SetAsSortedSet(B base,
Comparator<? super E> comparator,
Comparator<Bound<E>> boundComparator,
Bound<E> fromElement,
Bound<E> toElement)
Creates a new SetAsSortedSet with the specified
properties. |
Method Summary | ||
---|---|---|
Comparator<? super E> |
comparator()
Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering. |
|
protected int |
compare(Bound<E> o1,
Bound<E> o2)
Compares its two arguments for order using a comparator with infinities. |
|
boolean |
containsAll(Collection<?> c)
Returns true if this set contains all of the elements
of the specified collection. |
|
E |
first()
Returns the first (lowest) element currently in this sorted set. |
|
protected Comparator<Bound<E>> |
getBoundComparator()
Returns the comparator of this set taking infinity into account. |
|
protected Bound<E> |
getFromElement()
Returns the lower bound of this SortedSet . |
|
protected SortedSet<E> |
getSubSet(Bound<E> fromElement,
Bound<E> toElement)
Common method to create head, tail and sub sets. |
|
protected Bound<E> |
getToElement()
Returns the upper bound of this SortedSet . |
|
SortedSet<E> |
headSet(E toElement)
Returns a view of the portion of this sorted set whose elements are strictly less than toElement . |
|
E |
last()
Returns the last (highest) element currently in this sorted set. |
|
static
|
newInstance(Collection<E> base,
Comparator<? super E> comparator)
Constructs a SetAsSortedSet object. |
|
boolean |
removeAll(Collection<?> c)
Removes from this set all of its elements that are contained in the specified collection. |
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this set that are contained in the specified collection. |
|
void |
setConsistent(boolean consistent)
Sets the consistency flag. |
|
SortedSet<E> |
subSet(E fromElement,
E toElement)
Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. |
|
SortedSet<E> |
tailSet(E fromElement)
Returns a view of the portion of this sorted set whose elements are greater than or equal to fromElement . |
|
protected boolean |
useMerge(Collection c)
This method determines if a merge algorithm is used for containsAll , removeAll and
retainAll for the specified collection. |
Methods inherited from class net.sf.molae.pipe.basic.CollectionAsSet |
---|
equals, hashCode, isSet, newInstance |
Methods inherited from class net.sf.molae.pipe.basic.CollectionProxy |
---|
add, addAll, clear, contains, isEmpty, iterator, remove, size, toArray, toArray |
Methods inherited from class net.sf.molae.pipe.basic.ObjectProxy |
---|
assertNotNull, getBase, toString, toVerboseString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
add, addAll, clear, contains, equals, hashCode, isEmpty, iterator, remove, size, toArray, toArray |
Constructor Detail |
---|
protected SetAsSortedSet(B base, Comparator<? super E> comparator, Comparator<Bound<E>> boundComparator, Bound<E> fromElement, Bound<E> toElement)
SetAsSortedSet
with the specified
properties.
This constructor is intended for classes that implement both
the SortedSet and its subsets.
base
- the underlying collectioncomparator
- the comparator that will be used to sort this set.
A null
value indicates that the elements' natural
ordering should be used.boundComparator
- the comparator that will be used to compare
bounds - used for subsets.fromElement
- low endpoint (inclusive) of the subSettoElement
- high endpoint (exclusive) of the subSet
ClassCastException
- if FromElement and
toElement cannot be compared to one another using
this set's comparator (or, if the set has no comparator,
using natural ordering).
IllegalArgumentException
- if fromElement is greater
than toElement.
NullPointerException
- if fromElement or
toElement is null and this set uses natural
order, or its comparator does not tolerate null elements
or if the base set is null
.public SetAsSortedSet(B base, Comparator<? super E> comparator)
base
- the underlying collectioncomparator
- the comparator that will be used to sort this set.
A null
value indicates that the elements' natural
ordering should be used.Method Detail |
---|
public final Comparator<? super E> comparator()
null
if it uses its elements' natural ordering.
comparator
in interface SortedSet<E>
null
if it uses its elements' natural orderingprotected Comparator<Bound<E>> getBoundComparator()
protected final Bound<E> getFromElement()
SortedSet
.
Returns negative infinity
if no such bound was specified.
SortedSet
.protected final Bound<E> getToElement()
SortedSet
.
Returns positive infinity
if no such bound was specified.
SortedSet
public static <E> SortedSet<E> newInstance(Collection<E> base, Comparator<? super E> comparator)
base
- the underlying collectioncomparator
- the comparator that will be used to sort this set.
A null
value indicates that the elements' natural
ordering should be used.public void setConsistent(boolean consistent)
consistent
- false
to indicate that the
Comparator
associated with this set is not consistent with
equals
.Comparator
protected boolean useMerge(Collection c)
containsAll
, removeAll
and
retainAll
for the specified collection.
By default the following conditions are checked:consistency flag
is set.
c
- a collection that is parameter of a bulk operation.
true
if a merge algorithm can be used for the
specified collection.public boolean containsAll(Collection<?> c)
true
if this set contains all of the elements
of the specified collection.
If possible,
a merging implementation is used,
where both iterators are run through only once.
Note that the comparator must be consistent with
CollectionAsSet.equals(Object)
for this implementation.
If it is not, set
consistent
to false
.
containsAll
in interface Collection<E>
containsAll
in interface Set<E>
containsAll
in class CollectionProxy<B extends Collection<E>,E>
c
- collection to be checked for containment in this collection
true
if this set contains all of the elements
of the specified collectionpublic boolean retainAll(Collection<?> c)
CollectionAsSet.equals(Object)
for this implementation.
If it is not, set
consistent
to false
.
retainAll
in interface Collection<E>
retainAll
in interface Set<E>
retainAll
in class CollectionProxy<B extends Collection<E>,E>
c
- elements to be removed from this set
UnsupportedOperationException
- depending on the base setpublic boolean removeAll(Collection<?> c)
CollectionAsSet.equals(Object)
for this implementation.
If it is not, set
consistent
to false
.
removeAll
in interface Collection<E>
removeAll
in interface Set<E>
removeAll
in class CollectionProxy<B extends Collection<E>,E>
c
- elements to be removed from this set
UnsupportedOperationException
- depending on the base setprotected int compare(Bound<E> o1, Bound<E> o2)
o1
- first object to compareo2
- second object to compare
protected SortedSet<E> getSubSet(Bound<E> fromElement, Bound<E> toElement)
fromElement
- low endpoint (inclusive) of the subSettoElement
- high endpoint (exclusive) of the subSet
public SortedSet<E> subSet(E fromElement, E toElement)
getSubSet
.
subSet
in interface SortedSet<E>
fromElement
- low endpoint (inclusive) of the subSet.toElement
- high endpoint (exclusive) of the subSet.
ClassCastException
- if FromElement and
toElement cannot be compared to one another using
this set's comparator (or, if the set has no comparator,
using natural ordering).
IllegalArgumentException
- if fromElement is greater than
toElement.
NullPointerException
- if fromElement or
toElement is null and this set uses natural
order, or its comparator does not tolerate null elements.public SortedSet<E> headSet(E toElement)
toElement
.
This implementation calls getSubSet()
with the
the fromElement
of this SortedSet
and
the specified toElement
.
headSet
in interface SortedSet<E>
toElement
- high endpoint (exclusive) of the headSet.
ClassCastException
- if toElement is not compatible
with this set's comparator (or, if the set has no comparator,
if toElement does not implement Comparable).
NullPointerException
- if toElement is null and
this sorted set does not tolerate null elements.
IllegalArgumentException
- if this set is itself a subSet,
headSet, or tailSet, and toElement is not within the
specified range of the subSet, headSet, or tailSet.public SortedSet<E> tailSet(E fromElement)
fromElement
.
This implementation calls getSubSet()
with
the specified fromElement
and
the toElement
of this SortedSet
.
tailSet
in interface SortedSet<E>
fromElement
- low endpoint (inclusive) of the tailSet.
ClassCastException
- if fromElement is not compatible
with this set's comparator (or, if the set has no comparator,
if fromElement does not implement Comparable).
NullPointerException
- if fromElement is null
and this sorted set does not tolerate null elements.
IllegalArgumentException
- if this set is itself a subSet,
headSet, or tailSet, and fromElement is not within the
specified range of the subSet, headSet, or tailSet.public E first()
first
in interface SortedSet<E>
NoSuchElementException
- sorted set is empty.public E last()
last
in interface SortedSet<E>
NoSuchElementException
- sorted set is empty.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |