Package org.apache.commons.collections4.multiset

# 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>`

public class PredicatedSortedMultiSet<E> extends PredicatedMultiSet<E> implements 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:
  - Serialized Form

- ## 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

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `PredicatedSortedMultiSet(SortedMultiSet<E> multiset, Predicate<? super E> predicate)`
  Constructor that wraps (not copies).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Comparator<? super E>`
  `comparator()`
  Returns the comparator associated with this sorted multiset, or null if it uses its elements' natural ordering.
  `protected SortedMultiSet<E>`
  `decorated()`
  Gets the decorated sorted multiset.
  `E`
  `first()`
  Returns the first (lowest) member.
  `E`
  `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, uniqueSet`

  ### Methods inherited from class org.apache.commons.collections4.collection.PredicatedCollection

  `add, addAll, builder, notNullBuilder, predicatedCollection, validate`

  ### Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator

  `clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, setCollection, size, toArray, toArray, toString`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.util.Collection

  `addAll, clear, contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

  ### Methods inherited from interface org.apache.commons.collections4.MultiSet

  `add, add, containsAll, entrySet, equals, getCount, hashCode, iterator, remove, remove, removeAll, retainAll, setCount, size, uniqueSet`

- ## Constructor Details

  - ### PredicatedSortedMultiSet

    protected PredicatedSortedMultiSet(SortedMultiSet<E> multiset, Predicate<? super E> predicate)
    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 null
      `predicate` - The predicate to use for validation, must not be null
    Throws:
      `NullPointerException` - if multiset or predicate is null
      `IllegalArgumentException` - 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 null
      `predicate` - The predicate to use for validation, must not be null
    Returns:
      A new predicated SortedMultiSet
    Throws:
      `NullPointerException` - if multiset or predicate is null
      `IllegalArgumentException` - if the multiset contains invalid elements

  - ### comparator

    public Comparator<? super E> comparator()
    Description copied from interface: `SortedMultiSet`
    Returns the comparator associated with this sorted multiset, or null if it uses its elements' natural ordering.
    Specified by:
      `comparator` in interface `SortedMultiSet<E>`
    Returns:
      The comparator in use, or null if natural ordering.

  - ### decorated

    protected SortedMultiSet<E> decorated()
    Gets the decorated sorted multiset.
    Overrides:
      `decorated` in class `PredicatedMultiSet<E>`
    Returns:
      The decorated multiset

  - ### first

    public E first()
    Description copied from interface: `SortedMultiSet`
    Returns the first (lowest) member.
    Specified by:
      `first` in interface `SortedMultiSet<E>`
    Returns:
      The first element in the sorted multiset.

  - ### last

    public E last()
    Description copied from interface: `SortedMultiSet`
    Returns the last (highest) member.
    Specified by:
      `last` in interface `SortedMultiSet<E>`
    Returns:
      The last element in the sorted multiset.