Class PredicatedSortedMultiSet<E>
java.lang.Object
org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
org.apache.commons.collections4.collection.PredicatedCollection<E>
org.apache.commons.collections4.multiset.PredicatedMultiSet<E>
org.apache.commons.collections4.multiset.PredicatedSortedMultiSet<E>
- Type Parameters:
E- The type held in the multiset
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,MultiSet<E>,SortedMultiSet<E>
Decorates another
SortedMultiSet to validate that additions
match a specified predicate.
This multiset exists to provide validation for the decorated multiset.
It is normally created to decorate an empty multiset.
If an object cannot be added to the multiset, an IllegalArgumentException
is thrown.
One usage would be to ensure that no null entries are added to the multiset.
SortedMultiSet<E> set =
PredicatedSortedMultiSet.predicatedSortedMultiSet(new TreeMultiSet<E>(),
NotNullPredicate.notNullPredicate());
- Since:
- 4.6.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.collections4.collection.PredicatedCollection
PredicatedCollection.Builder<E>Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSet
MultiSet.Entry<E> -
Field Summary
Fields inherited from class org.apache.commons.collections4.collection.PredicatedCollection
predicate -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPredicatedSortedMultiSet(SortedMultiSet<E> multiset, Predicate<? super E> predicate) Constructor that wraps (not copies). -
Method Summary
Modifier and TypeMethodDescriptionComparator<? super E> Returns the comparator associated with this sorted multiset, or null if it uses its elements' natural ordering.protected SortedMultiSet<E> Gets the decorated sorted multiset.first()Returns the first (lowest) member.last()Returns the last (highest) member.static <E> PredicatedSortedMultiSet<E> predicatedSortedMultiSet(SortedMultiSet<E> multiset, Predicate<? super E> predicate) Factory method to create a predicated (validating) multiset.Methods inherited from class org.apache.commons.collections4.multiset.PredicatedMultiSet
add, entrySet, equals, getCount, hashCode, predicatedMultiSet, remove, setCount, uniqueSetMethods inherited from class org.apache.commons.collections4.collection.PredicatedCollection
add, addAll, builder, notNullBuilder, predicatedCollection, validateMethods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, clear, contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
-
Constructor Details
-
PredicatedSortedMultiSet
Constructor that wraps (not copies).If there are any elements already in the multiset being decorated, they are validated.
- Parameters:
multiset- The multiset to decorate, must not be nullpredicate- The predicate to use for validation, must not be null- Throws:
NullPointerException- if multiset or predicate is nullIllegalArgumentException- if the multiset contains invalid elements
-
-
Method Details
-
predicatedSortedMultiSet
public static <E> PredicatedSortedMultiSet<E> predicatedSortedMultiSet(SortedMultiSet<E> multiset, Predicate<? super E> predicate) Factory method to create a predicated (validating) multiset.If there are any elements already in the multiset being decorated, they are validated.
- Type Parameters:
E- The type of the elements in the multiset- Parameters:
multiset- The multiset to decorate, must not be nullpredicate- The predicate to use for validation, must not be null- Returns:
- A new predicated SortedMultiSet
- Throws:
NullPointerException- if multiset or predicate is nullIllegalArgumentException- if the multiset contains invalid elements
-
comparator
Description copied from interface:SortedMultiSetReturns the comparator associated with this sorted multiset, or null if it uses its elements' natural ordering.- Specified by:
comparatorin interfaceSortedMultiSet<E>- Returns:
- The comparator in use, or null if natural ordering.
-
decorated
Gets the decorated sorted multiset.- Overrides:
decoratedin classPredicatedMultiSet<E>- Returns:
- The decorated multiset
-
first
Description copied from interface:SortedMultiSetReturns the first (lowest) member.- Specified by:
firstin interfaceSortedMultiSet<E>- Returns:
- The first element in the sorted multiset.
-
last
Description copied from interface:SortedMultiSetReturns the last (highest) member.- Specified by:
lastin interfaceSortedMultiSet<E>- Returns:
- The last element in the sorted multiset.
-