Class ForwardingSortedMultiset.StandardElementSet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.google.common.collect.ForwardingSortedMultiset.StandardElementSet
-
- All Implemented Interfaces:
Iterable<E>,Collection<E>,NavigableSet<E>,Set<E>,SortedSet<E>
- Enclosing class:
- ForwardingSortedMultiset<E extends @Nullable Object>
protected class ForwardingSortedMultiset.StandardElementSet extends AbstractSet<E>
A sensible implementation ofSortedMultiset.elementSet()in terms of the following methods:Collection.clear(),SortedMultiset.comparator(),Multiset.contains(java.lang.Object),Multiset.containsAll(java.util.Collection<?>),Multiset.count(java.lang.Object),SortedMultiset.firstEntry()SortedMultiset.headMultiset(E, com.google.common.collect.BoundType),Collection.isEmpty(),SortedMultiset.lastEntry(),SortedMultiset.subMultiset(E, com.google.common.collect.BoundType, E, com.google.common.collect.BoundType),SortedMultiset.tailMultiset(E, com.google.common.collect.BoundType), thesize()anditerator()methods ofSortedMultiset.entrySet(), andMultiset.remove(Object, int). In many situations, you may wish to overrideSortedMultiset.elementSet()to forward to this implementation or a subclass thereof.- Since:
- 15.0
-
-
Constructor Summary
Constructors Constructor Description StandardElementSet()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Eceiling(E e)Returns the least element in this set greater than or equal to the given element, ornullif there is no such element.voidclear()Removes all of the elements from this collection (optional operation).Comparator<? super E>comparator()Returns the comparator used to order the elements in this set, ornullif this set uses the natural ordering of its elements.booleancontains(Object o)Returnstrueif this collection contains the specified element.booleancontainsAll(Collection<?> c)Returnstrueif this collection contains all of the elements in the specified collection.Iterator<E>descendingIterator()Returns an iterator over the elements in this set, in descending order.NavigableSet<E>descendingSet()Returns a reverse order view of the elements contained in this set.Efirst()Returns the first (lowest) element currently in this set.Efloor(E e)Returns the greatest element in this set less than or equal to the given element, ornullif there is no such element.SortedSet<E>headSet(E toElement)Returns a view of the portion of this set whose elements are strictly less thantoElement.NavigableSet<E>headSet(E toElement, boolean inclusive)Returns a view of the portion of this set whose elements are less than (or equal to, ifinclusiveis true)toElement.Ehigher(E e)Returns the least element in this set strictly greater than the given element, ornullif there is no such element.booleanisEmpty()Returnstrueif this collection contains no elements.Iterator<E>iterator()Returns an iterator over the elements contained in this collection.Elast()Returns the last (highest) element currently in this set.Elower(E e)Returns the greatest element in this set strictly less than the given element, ornullif there is no such element.EpollFirst()Retrieves and removes the first (lowest) element, or returnsnullif this set is empty.EpollLast()Retrieves and removes the last (highest) element, or returnsnullif this set is empty.booleanremove(Object o)Removes a single instance of the specified element from this collection, if it is present (optional operation).booleanremoveAll(Collection<?> c)Removes from this set all of its elements that are contained in the specified collection (optional operation).booleanretainAll(Collection<?> c)Retains only the elements in this collection that are contained in the specified collection (optional operation).intsize()Returns the number of elements in this collection.NavigableSet<E>subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)Returns a view of the portion of this set whose elements range fromfromElementtotoElement.SortedSet<E>subSet(E fromElement, E toElement)Returns a view of the portion of this set whose elements range fromfromElement, inclusive, totoElement, exclusive.SortedSet<E>tailSet(E fromElement)Returns a view of the portion of this set whose elements are greater than or equal tofromElement.NavigableSet<E>tailSet(E fromElement, boolean inclusive)Returns a view of the portion of this set whose elements are greater than (or equal to, ifinclusiveis true)fromElement.-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.NavigableSet
headSet, iterator, subSet, tailSet
-
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
-
Methods inherited from interface java.util.SortedSet
comparator, first, last, spliterator
-
-
-
-
Constructor Detail
-
StandardElementSet
public StandardElementSet()
Constructor for use by subclasses.
-
-
Method Detail
-
lower
@CheckForNull public E lower(E e)
Description copied from interface:java.util.NavigableSetReturns the greatest element in this set strictly less than the given element, ornullif there is no such element.- Specified by:
lowerin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the greatest element less than
e, ornullif there is no such element
-
floor
@CheckForNull public E floor(E e)
Description copied from interface:java.util.NavigableSetReturns the greatest element in this set less than or equal to the given element, ornullif there is no such element.- Specified by:
floorin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the greatest element less than or equal to
e, ornullif there is no such element
-
ceiling
@CheckForNull public E ceiling(E e)
Description copied from interface:java.util.NavigableSetReturns the least element in this set greater than or equal to the given element, ornullif there is no such element.- Specified by:
ceilingin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the least element greater than or equal to
e, ornullif there is no such element
-
higher
@CheckForNull public E higher(E e)
Description copied from interface:java.util.NavigableSetReturns the least element in this set strictly greater than the given element, ornullif there is no such element.- Specified by:
higherin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the least element greater than
e, ornullif there is no such element
-
descendingSet
public NavigableSet<E> descendingSet()
Description copied from interface:java.util.NavigableSetReturns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iteration over either set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined.The returned set has an ordering equivalent to
Collections.reverseOrder(comparator()). The expressions.descendingSet().descendingSet()returns a view ofsessentially equivalent tos.- Specified by:
descendingSetin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- a reverse order view of this set
-
descendingIterator
public Iterator<E> descendingIterator()
Description copied from interface:java.util.NavigableSetReturns an iterator over the elements in this set, in descending order. Equivalent in effect todescendingSet().iterator().- Specified by:
descendingIteratorin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- an iterator over the elements in this set, in descending order
-
pollFirst
@CheckForNull public E pollFirst()
Description copied from interface:java.util.NavigableSetRetrieves and removes the first (lowest) element, or returnsnullif this set is empty.- Specified by:
pollFirstin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- the first element, or
nullif this set is empty
-
pollLast
@CheckForNull public E pollLast()
Description copied from interface:java.util.NavigableSetRetrieves and removes the last (highest) element, or returnsnullif this set is empty.- Specified by:
pollLastin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- the last element, or
nullif this set is empty
-
subSet
public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements range fromfromElementtotoElement. IffromElementandtoElementare equal, the returned set is empty unlessfromInclusiveandtoInclusiveare both true. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.The returned set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
subSetin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
fromElement- low endpoint of the returned setfromInclusive-trueif the low endpoint is to be included in the returned viewtoElement- high endpoint of the returned settoInclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this set whose elements range from
fromElement, inclusive, totoElement, exclusive
-
headSet
public NavigableSet<E> headSet(E toElement, boolean inclusive)
Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements are less than (or equal to, ifinclusiveis true)toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.The returned set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
headSetin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
toElement- high endpoint of the returned setinclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this set whose elements are less than
(or equal to, if
inclusiveis true)toElement
-
tailSet
public NavigableSet<E> tailSet(E fromElement, boolean inclusive)
Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements are greater than (or equal to, ifinclusiveis true)fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.The returned set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
tailSetin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
fromElement- low endpoint of the returned setinclusive-trueif the low endpoint is to be included in the returned view- Returns:
- a view of the portion of this set whose elements are greater
than or equal to
fromElement
-
iterator
public Iterator<E> iterator()
Description copied from class:java.util.AbstractCollectionReturns an iterator over the elements contained in this collection.
-
comparator
public Comparator<? super E> comparator()
Description copied from interface:java.util.SortedSetReturns the comparator used to order the elements in this set, ornullif this set uses the natural ordering of its elements.- Specified by:
comparatorin interfaceSortedSet<E extends @Nullable Object>- Returns:
- the comparator used to order the elements in this set,
or
nullif this set uses the natural ordering of its elements
-
subSet
public SortedSet<E> subSet(E fromElement, E toElement)
Description copied from interface:java.util.SortedSetReturns a view of the portion of this set whose elements range fromfromElement, inclusive, totoElement, exclusive. (IffromElementandtoElementare equal, the returned set is empty.) The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.The returned set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
subSetin interfaceSortedSet<E extends @Nullable Object>- Parameters:
fromElement- low endpoint (inclusive) of the returned settoElement- high endpoint (exclusive) of the returned set- Returns:
- a view of the portion of this set whose elements range from
fromElement, inclusive, totoElement, exclusive
-
headSet
public SortedSet<E> headSet(E toElement)
Description copied from interface:java.util.SortedSetReturns a view of the portion of this set whose elements are strictly less thantoElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.The returned set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.
-
tailSet
public SortedSet<E> tailSet(E fromElement)
Description copied from interface:java.util.SortedSetReturns a view of the portion of this set whose elements are greater than or equal tofromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.The returned set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.
-
first
public E first()
Description copied from interface:java.util.SortedSetReturns the first (lowest) element currently in this set.
-
last
public E last()
Description copied from interface:java.util.SortedSetReturns the last (highest) element currently in this set.
-
clear
public void clear()
Description copied from class:java.util.AbstractCollectionRemoves all of the elements from this collection (optional operation). The collection will be empty after this method returns.
-
contains
public boolean contains(@CheckForNull Object o)
Description copied from class:java.util.AbstractCollectionReturnstrueif this collection contains the specified element. More formally, returnstrueif and only if this collection contains at least one elementesuch thatObjects.equals(o, e).- Specified by:
containsin interfaceCollection<E extends @Nullable Object>- Specified by:
containsin interfaceSet<E extends @Nullable Object>- Overrides:
containsin classAbstractCollection<E extends @Nullable Object>- Parameters:
o- element whose presence in this collection is to be tested- Returns:
trueif this collection contains the specified element
-
containsAll
public boolean containsAll(Collection<?> c)
Description copied from class:java.util.AbstractCollectionReturnstrueif this collection contains all of the elements in the specified collection.- Specified by:
containsAllin interfaceCollection<E extends @Nullable Object>- Specified by:
containsAllin interfaceSet<E extends @Nullable Object>- Overrides:
containsAllin classAbstractCollection<E extends @Nullable Object>- Parameters:
c- collection to be checked for containment in this collection- Returns:
trueif this collection contains all of the elements in the specified collection- See Also:
AbstractCollection.contains(Object)
-
isEmpty
public boolean isEmpty()
Description copied from class:java.util.AbstractCollectionReturnstrueif this collection contains no elements.
-
remove
public boolean remove(@CheckForNull Object o)
Description copied from class:java.util.AbstractCollectionRemoves a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an elementesuch thatObjects.equals(o, e), if this collection contains one or more such elements. Returnstrueif this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
removein interfaceCollection<E extends @Nullable Object>- Specified by:
removein interfaceSet<E extends @Nullable Object>- Overrides:
removein classAbstractCollection<E extends @Nullable Object>- Parameters:
o- element to be removed from this collection, if present- Returns:
trueif an element was removed as a result of this call
-
size
public int size()
Description copied from interface:java.util.CollectionReturns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.
-
removeAll
public boolean removeAll(Collection<?> c)
Description copied from class:java.util.AbstractSetRemoves from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.This implementation determines which is the smaller of this set and the specified collection, by invoking the
sizemethod on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is so contained, it is removed from this set with the iterator'sremovemethod. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this set'sremovemethod.Note that this implementation will throw an
UnsupportedOperationExceptionif the iterator returned by theiteratormethod does not implement theremovemethod.- Specified by:
removeAllin interfaceCollection<E extends @Nullable Object>- Specified by:
removeAllin interfaceSet<E extends @Nullable Object>- Overrides:
removeAllin classAbstractSet<E extends @Nullable Object>- Parameters:
c- collection containing elements to be removed from this set- Returns:
trueif this set changed as a result of the call- See Also:
AbstractCollection.remove(Object),AbstractCollection.contains(Object)
-
retainAll
public boolean retainAll(Collection<?> c)
Description copied from class:java.util.AbstractCollectionRetains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.- Specified by:
retainAllin interfaceCollection<E extends @Nullable Object>- Specified by:
retainAllin interfaceSet<E extends @Nullable Object>- Overrides:
retainAllin classAbstractCollection<E extends @Nullable Object>- Parameters:
c- collection containing elements to be retained in this collection- Returns:
trueif this collection changed as a result of the call- See Also:
AbstractCollection.remove(Object),AbstractCollection.contains(Object)
-
-