|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.collect.ExternallySortedSet<T,C>
public class ExternallySortedSet<T,C extends Comparable<? super C>>
A container class that almost implements the SortedSet interface;
the difference is that add() takes two parameters -- an element, along with a
corresponding Comparable that will be used to sort the set. Thus, the set is not
sorted based on any operations defined for the element type; rather, it is sorted according
to an external orderBy value. The subSet(), etc., methods are also adjusted
to take in orderBy values rather than set elements.
The result is a set that works essentially like a TreeSet
of Pairs in which one of the Pair elements is a Comparable,
and for which a Comparator is correctly defined. One significant difference is that this
implementation does not return true for the expression add(1, 1) && add(1, 2),
while the explicit Pair implementation would (assuming the Set were initially empty).
Note: the implementation relies heavily on hashing, so good performance is
dependent on elements of the set having an efficient hashCode() implementation.
| Constructor Summary | |
|---|---|
ExternallySortedSet()
Creates an empty set. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(T element,
C orderBy)
Add element to the set, sorted by orderBy. |
|
boolean |
addAll(ExternallySortedSet<? extends T,? extends C> s)
Add every element of s to this set (if it is not already present). |
|
void |
clear()
Removes every element of this set. |
|
boolean |
contains(Object element)
|
|
boolean |
containsAll(Iterable<?> i)
|
|
T |
first()
|
|
boolean |
hasFixedSize()
true if this iterable is known to have a fixed size. |
|
ExternallySortedSet<T,C> |
headSet(C to)
|
|
boolean |
isEmpty()
Whether the iterable does not contain any elements. |
|
boolean |
isInfinite()
true if the iterable is known to have infinite size. |
|
boolean |
isStatic()
true if this iterable is unchanging. |
|
Iterator<T> |
iterator()
|
|
T |
last()
|
|
boolean |
remove(Object element)
Removes the element specified from the set. |
|
boolean |
removeAll(Iterable<?> i)
Removes every element of this set that is in c. |
|
boolean |
retainAll(Collection<?> c)
Removes every element of this set that is not in c. |
|
boolean |
retainAll(ExternallySortedSet<?,?> s)
Removes every element of this set that is not in s. |
|
int |
size()
Compute the number of elements in the iterable. |
|
int |
size(int bound)
Compute the number of elements in the iterable, up to the given bound. |
|
ExternallySortedSet<T,C> |
subSet(C from,
C to)
|
|
ExternallySortedSet<T,C> |
tailSet(C from)
|
|
Object[] |
toArray()
|
|
|
toArray(S[] a)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ExternallySortedSet()
| Method Detail |
|---|
public boolean isEmpty()
SizedIterable
isEmpty in interface SizedIterable<T>public int size()
SizedIterableint, Integer.MAX_VALUE should be returned. Otherwise, next() may be safely invoked
on the iterator exactly this number of times.
size in interface SizedIterable<T>public int size(int bound)
SizedIterablebound, bound is returned.
size in interface SizedIterable<T>bound - Maximum result. Assumed to be nonnegative.public boolean isInfinite()
SizedIterabletrue if the iterable is known to have infinite size. If true, an iterator over the iterable in its
current state will never return false from hasNext().
isInfinite in interface SizedIterable<T>public boolean hasFixedSize()
SizedIterabletrue if this iterable is known to have a fixed size. This is the case if the iterable is immutable,
or if changes can only replace values, not remove or add them. An infinite iterable may be fixed if it
is guaranteed to never become finite.
hasFixedSize in interface SizedIterable<T>public boolean isStatic()
SizedIterabletrue if this iterable is unchanging. This implies that hasFixedSize() is true, and that
iterator() will always return the same (either == or equal() and immutable) elements
in the same order. ("Immutable" here means that equals() invocations are consistent over time -- if
two objects are equal, they will never become inequal, and vice versa.)
isStatic in interface SizedIterable<T>public boolean contains(Object element)
public Iterator<T> iterator()
iterator in interface Iterable<T>Iterator.remove().public Object[] toArray()
Set interface,
changes to the array will not be reflected in the set.public <S> S[] toArray(S[] a)
Set interface,
changes to the array will not be reflected in the set.
public boolean add(T element,
C orderBy)
element to the set, sorted by orderBy.
true iff element was not already in the set and could be added.
IllegalArgumentException - if this is a subset of a larger set, and the
element being added is outside the specified bounds.
NullPointerException - if element is nullpublic boolean remove(Object element)
true iff the set contained element.public boolean containsAll(Iterable<?> i)
true iff the set contains each of the elements in i.public boolean addAll(ExternallySortedSet<? extends T,? extends C> s)
s to this set (if it is not already present).
true iff the operation modified this set.public boolean retainAll(Collection<?> c)
c.
true iff the operation modified this set.public boolean retainAll(ExternallySortedSet<?,?> s)
s.
true iff the operation modified this set.public boolean removeAll(Iterable<?> i)
c.
true iff the operation modified this set.public void clear()
public ExternallySortedSet<T,C> subSet(C from,
C to)
from (inclusive)
to to (exclusive). The result is backed by this set and bounded by
from and to; changes to either this or the result are
reflected by both.
IllegalArgumentException - if from or to is outside this set's boundspublic ExternallySortedSet<T,C> headSet(C to)
to (exclusive).
The result is backed by this set, so changes to either are reflected by both.
IllegalArgumentException - if to is outside this set's boundspublic ExternallySortedSet<T,C> tailSet(C from)
from (inclusive).
The result is backed by this set, so changes to either are reflected by both.
IllegalArgumentException - if from is outside this set's boundspublic T first()
public T last()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||