Class ForwardingSortedMultiset.StandardElementSet
-
- <E>
-
- <E>
-
- com.google.common.collect.ForwardingSortedMultiset.StandardElementSet
-
- All Implemented Interfaces:
<E>
,<E>
,<E>
,<E>
,<E>
- Enclosing class:
- ForwardingSortedMultiset<E>
protected class ForwardingSortedMultiset.StandardElementSet extends <E>
A sensible implementation ofSortedMultiset.elementSet()
in terms of the following methods: ,SortedMultiset.comparator()
,Multiset.contains(java.lang.Object)
,Multiset.containsAll(java.util.Collection<?>)
,Multiset.count(java.lang.Object)
, ,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 E
ceiling(E e)
Returns the least element in this set greater than or equal to the given element, ornull
if there is no such element.void
clear()
Removes all of the elements from this collection (optional operation).<? super E>
comparator()
Returns the comparator used to order the elements in this set, ornull
if this set uses the of its elements.boolean
o)
Returnstrue
if this collection contains the specified element.boolean
<?> c)
Returnstrue
if this collection contains all of the elements in the specified collection.<E>
descendingIterator()
Returns an iterator over the elements in this set, in descending order.<E>
descendingSet()
Returns a reverse order view of the elements contained in this set.E
first()
Returns the first (lowest) element currently in this set.E
floor(E e)
Returns the greatest element in this set less than or equal to the given element, ornull
if there is no such element.<E>
headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly less thantoElement
.<E>
headSet(E toElement, boolean inclusive)
Returns a view of the portion of this set whose elements are less than (or equal to, ifinclusive
is true)toElement
.E
higher(E e)
Returns the least element in this set strictly greater than the given element, ornull
if there is no such element.boolean
isEmpty()
Returnstrue
if this collection contains no elements.<E>
iterator()
Returns an iterator over the elements contained in this collection.E
last()
Returns the last (highest) element currently in this set.E
lower(E e)
Returns the greatest element in this set strictly less than the given element, ornull
if there is no such element.E
pollFirst()
Retrieves and removes the first (lowest) element, or returnsnull
if this set is empty.E
pollLast()
Retrieves and removes the last (highest) element, or returnsnull
if this set is empty.boolean
o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).boolean
<?> c)
Removes from this set all of its elements that are contained in the specified collection (optional operation).boolean
<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).int
size()
Returns the number of elements in this collection.<E>
subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
Returns a view of the portion of this set whose elements range fromfromElement
totoElement
.<E>
subSet(E fromElement, E toElement)
Returns a view of the portion of this set whose elements range fromfromElement
, inclusive, totoElement
, exclusive.<E>
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are greater than or equal tofromElement
.<E>
tailSet(E fromElement, boolean inclusive)
Returns a view of the portion of this set whose elements are greater than (or equal to, ifinclusive
is true)fromElement
.
-
-
-
Constructor Detail
-
StandardElementSet
public StandardElementSet()
Constructor for use by subclasses.
-
-
Method Detail
-
lower
public E lower(E e)
Description copied from interface:Returns the greatest element in this set strictly less than the given element, ornull
if there is no such element.- Specified by:
in interface
<E>
- Parameters:
e
- the value to match- Returns:
- the greatest element less than
e
, ornull
if there is no such element
-
floor
public E floor(E e)
Description copied from interface:Returns the greatest element in this set less than or equal to the given element, ornull
if there is no such element.- Specified by:
in interface
<E>
- Parameters:
e
- the value to match- Returns:
- the greatest element less than or equal to
e
, ornull
if there is no such element
-
ceiling
public E ceiling(E e)
Description copied from interface:Returns the least element in this set greater than or equal to the given element, ornull
if there is no such element.- Specified by:
in interface
<E>
- Parameters:
e
- the value to match- Returns:
- the least element greater than or equal to
e
, ornull
if there is no such element
-
higher
public E higher(E e)
Description copied from interface:Returns the least element in this set strictly greater than the given element, ornull
if there is no such element.- Specified by:
in interface
<E>
- Parameters:
e
- the value to match- Returns:
- the least element greater than
e
, ornull
if there is no such element
-
descendingSet
public <E> descendingSet()
Description copied from interface:Returns 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 ownremove
operation), the results of the iteration are undefined.The returned set has an ordering equivalent to
(comparator())
. The expressions.descendingSet().descendingSet()
returns a view ofs
essentially equivalent tos
.- Specified by:
in interface
<E>
- Returns:
- a reverse order view of this set
-
descendingIterator
public <E> descendingIterator()
Description copied from interface:Returns an iterator over the elements in this set, in descending order. Equivalent in effect todescendingSet().iterator()
.- Specified by:
in interface
<E>
- Returns:
- an iterator over the elements in this set, in descending order
-
pollFirst
public E pollFirst()
Description copied from interface:Retrieves and removes the first (lowest) element, or returnsnull
if this set is empty.- Specified by:
in interface
<E>
- Returns:
- the first element, or
null
if this set is empty
-
pollLast
public E pollLast()
Description copied from interface:Retrieves and removes the last (highest) element, or returnsnull
if this set is empty.- Specified by:
in interface
<E>
- Returns:
- the last element, or
null
if this set is empty
-
subSet
public <E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
Description copied from interface:Returns a view of the portion of this set whose elements range fromfromElement
totoElement
. IffromElement
andtoElement
are equal, the returned set is empty unlessfromInclusive
andtoInclusive
are 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
IllegalArgumentException
on an attempt to insert an element outside its range.- Specified by:
in interface
<E>
- Parameters:
fromElement
- low endpoint of the returned setfromInclusive
-true
if the low endpoint is to be included in the returned viewtoElement
- high endpoint of the returned settoInclusive
-true
if 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 <E> headSet(E toElement, boolean inclusive)
Description copied from interface:Returns a view of the portion of this set whose elements are less than (or equal to, ifinclusive
is 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
IllegalArgumentException
on an attempt to insert an element outside its range.- Specified by:
in interface
<E>
- Parameters:
toElement
- high endpoint of the returned setinclusive
-true
if 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
inclusive
is true)toElement
-
tailSet
public <E> tailSet(E fromElement, boolean inclusive)
Description copied from interface:Returns a view of the portion of this set whose elements are greater than (or equal to, ifinclusive
is 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
IllegalArgumentException
on an attempt to insert an element outside its range.- Specified by:
in interface
<E>
- Parameters:
fromElement
- low endpoint of the returned setinclusive
-true
if 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 <E> iterator()
Description copied from class:Returns an iterator over the elements contained in this collection.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Returns:
- an iterator over the elements contained in this collection
-
comparator
public <? super E> comparator()
Description copied from interface:Returns the comparator used to order the elements in this set, ornull
if this set uses the of its elements.- Specified by:
in interface
<E>
- Returns:
- the comparator used to order the elements in this set,
or
null
if this set uses the natural ordering of its elements
-
subSet
public <E> subSet(E fromElement, E toElement)
Description copied from interface:Returns a view of the portion of this set whose elements range fromfromElement
, inclusive, totoElement
, exclusive. (IffromElement
andtoElement
are 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
IllegalArgumentException
on an attempt to insert an element outside its range.- Specified by:
in interface
<E>
- 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 <E> headSet(E toElement)
Description copied from interface:Returns 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
IllegalArgumentException
on an attempt to insert an element outside its range.- Specified by:
in interface
<E>
- Parameters:
toElement
- high endpoint (exclusive) of the returned set- Returns:
- a view of the portion of this set whose elements are strictly
less than
toElement
-
tailSet
public <E> tailSet(E fromElement)
Description copied from interface:Returns 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
IllegalArgumentException
on an attempt to insert an element outside its range.- Specified by:
in interface
<E>
- Parameters:
fromElement
- low endpoint (inclusive) of the returned set- Returns:
- a view of the portion of this set whose elements are greater
than or equal to
fromElement
-
first
public E first()
Description copied from interface:Returns the first (lowest) element currently in this set.- Specified by:
in interface
<E>
- Returns:
- the first (lowest) element currently in this set
-
last
public E last()
Description copied from interface:Returns the last (highest) element currently in this set.- Specified by:
in interface
<E>
- Returns:
- the last (highest) element currently in this set
-
clear
public void clear()
Description copied from class:Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
-
contains
public boolean contains( o)
Description copied from class:Returnstrue
if this collection contains the specified element. More formally, returnstrue
if and only if this collection contains at least one elemente
such thatObjects.equals(o, e)
.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
- Parameters:
o
- element whose presence in this collection is to be tested- Returns:
true
if this collection contains the specified element
-
containsAll
public boolean containsAll(<?> c)
Description copied from class:Returnstrue
if this collection contains all of the elements in the specified collection.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
- Parameters:
c
- collection to be checked for containment in this collection- Returns:
true
if this collection contains all of the elements in the specified collection- See Also:
-
isEmpty
public boolean isEmpty()
Description copied from class:Returnstrue
if this collection contains no elements.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
- Returns:
true
if this collection contains no elements
-
remove
public boolean remove( o)
Description copied from class:Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an elemente
such thatObjects.equals(o, e)
, if this collection contains one or more such elements. Returnstrue
if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
- Parameters:
o
- element to be removed from this collection, if present- Returns:
true
if an element was removed as a result of this call
-
size
public int size()
Description copied from interface:Returns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Specified by:
in class
<E>
- Returns:
- the number of elements in this collection
-
removeAll
public boolean removeAll(<?> c)
Description copied from class:Removes 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
size
method 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'sremove
method. 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'sremove
method.Note that this implementation will throw an
UnsupportedOperationException
if the iterator returned by theiterator
method does not implement theremove
method.- Specified by:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
- Parameters:
c
- collection containing elements to be removed from this set- Returns:
true
if this set changed as a result of the call- See Also:
- ,
-
retainAll
public boolean retainAll(<?> c)
Description copied from class:Retains 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:
in interface
<E>
- Specified by:
in interface
<E>
- Overrides:
in class
<E>
- Parameters:
c
- collection containing elements to be retained in this collection- Returns:
true
if this collection changed as a result of the call- See Also:
- ,
-
-