E
- the element typepublic static class PredicatedCollection.Builder<E>
extends java.lang.Object
Create a Builder with a predicate to validate elements against, then add any elements to the builder. Elements that fail the predicate will be added to a rejected list. Finally create or decorate a collection using the createPredicated[List,Set,Bag,Queue] methods.
An example:
Predicate<String> predicate = NotNullPredicate.notNullPredicate(); PredicatedCollectionBuilder<String> builder = PredicatedCollection.builder(predicate); builder.add("item1"); builder.add(null); builder.add("item2"); List<String> predicatedList = builder.createPredicatedList();
At the end of the code fragment above predicatedList is protected by the predicate supplied to the builder and it contains item1 and item2.
More elements can be added to the builder once a predicated collection has been created, but these elements will not be reflected in already created collections.
Constructor and Description |
---|
Builder(Predicate<? super E> predicate)
Constructs a PredicatedCollectionBuilder with the specified Predicate.
|
Modifier and Type | Method and Description |
---|---|
PredicatedCollection.Builder<E> |
add(E item)
Adds the item to the builder.
|
PredicatedCollection.Builder<E> |
addAll(java.util.Collection<? extends E> items)
Adds all elements from the given collection to the builder.
|
Bag<E> |
createPredicatedBag()
Create a new predicated bag filled with the accepted elements.
|
Bag<E> |
createPredicatedBag(Bag<E> bag)
Decorates the given bag with validating behavior using the predicate.
|
java.util.List<E> |
createPredicatedList()
Create a new predicated list filled with the accepted elements.
|
java.util.List<E> |
createPredicatedList(java.util.List<E> list)
Decorates the given list with validating behavior using the predicate.
|
MultiSet<E> |
createPredicatedMultiSet()
Create a new predicated multiset filled with the accepted elements.
|
MultiSet<E> |
createPredicatedMultiSet(MultiSet<E> multiset)
Decorates the given multiset with validating behavior using the predicate.
|
java.util.Queue<E> |
createPredicatedQueue()
Create a new predicated queue filled with the accepted elements.
|
java.util.Queue<E> |
createPredicatedQueue(java.util.Queue<E> queue)
Decorates the given queue with validating behavior using the predicate.
|
java.util.Set<E> |
createPredicatedSet()
Create a new predicated set filled with the accepted elements.
|
java.util.Set<E> |
createPredicatedSet(java.util.Set<E> set)
Decorates the given list with validating behavior using the predicate.
|
java.util.Collection<E> |
rejectedElements()
Returns an unmodifiable collection containing all rejected elements.
|
public PredicatedCollection.Builder<E> add(E item)
If the predicate is true, it is added to the list of accepted elements, otherwise it is added to the rejected list.
item
- the element to addpublic PredicatedCollection.Builder<E> addAll(java.util.Collection<? extends E> items)
All elements for which the predicate evaluates to true will be added to the list of accepted elements, otherwise they are added to the rejected list.
items
- the elements to add to the builderpublic java.util.List<E> createPredicatedList()
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned list.
public java.util.List<E> createPredicatedList(java.util.List<E> list)
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned list.
list
- the List to decorate, must not be nulljava.lang.NullPointerException
- if list is nulljava.lang.IllegalArgumentException
- if list contains invalid elementspublic java.util.Set<E> createPredicatedSet()
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned set.
public java.util.Set<E> createPredicatedSet(java.util.Set<E> set)
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned set.
set
- the set to decorate, must not be nulljava.lang.NullPointerException
- if set is nulljava.lang.IllegalArgumentException
- if set contains invalid elementspublic MultiSet<E> createPredicatedMultiSet()
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned multiset.
public MultiSet<E> createPredicatedMultiSet(MultiSet<E> multiset)
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned multiset.
multiset
- the multiset to decorate, must not be nulljava.lang.NullPointerException
- if multiset is nulljava.lang.IllegalArgumentException
- if multiset contains invalid elementspublic Bag<E> createPredicatedBag()
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned bag.
public Bag<E> createPredicatedBag(Bag<E> bag)
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned bag.
bag
- the bag to decorate, must not be nulljava.lang.NullPointerException
- if bag is nulljava.lang.IllegalArgumentException
- if bag contains invalid elementspublic java.util.Queue<E> createPredicatedQueue()
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned queue.
public java.util.Queue<E> createPredicatedQueue(java.util.Queue<E> queue)
The builder is not modified by this method, so it is possible to create more collections or add more elements afterwards. Further changes will not propagate to the returned queue.
queue
- the queue to decorate, must not be nulljava.lang.NullPointerException
- if queue is nulljava.lang.IllegalArgumentException
- if queue contains invalid elementspublic java.util.Collection<E> rejectedElements()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"