Class PredicatedCollection.Builder<E>
- Type Parameters:
- E- the element type
- Enclosing class:
- PredicatedCollection<E>
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.
- Since:
- 4.1
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionAdds the item to the builder.addAll(Collection<? extends E> items) Adds all elements from the given collection to the builder.Create a new predicated bag filled with the accepted elements.createPredicatedBag(Bag<E> bag) Decorates the given bag with validating behavior using the predicate.Create a new predicated list filled with the accepted elements.createPredicatedList(List<E> list) Decorates the given list with validating behavior using the predicate.Create a new predicated multiset filled with the accepted elements.createPredicatedMultiSet(MultiSet<E> multiset) Decorates the given multiset with validating behavior using the predicate.Create a new predicated queue filled with the accepted elements.createPredicatedQueue(Queue<E> queue) Decorates the given queue with validating behavior using the predicate.Create a new predicated set filled with the accepted elements.createPredicatedSet(Set<E> set) Decorates the given list with validating behavior using the predicate.Returns an unmodifiable collection containing all rejected elements.
- 
Constructor Details- 
BuilderConstructs a PredicatedCollectionBuilder with the specified Predicate.- Parameters:
- predicate- the predicate to use
- Throws:
- NullPointerException- if predicate is null
 
 
- 
- 
Method Details- 
addAdds the item to the builder.If the predicate is true, it is added to the list of accepted elements, otherwise it is added to the rejected list. - Parameters:
- item- the element to add
- Returns:
- the PredicatedCollectionBuilder.
 
- 
addAllAdds all elements from the given collection to the builder.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. - Parameters:
- items- the elements to add to the builder
- Returns:
- the PredicatedCollectionBuilder.
 
- 
createPredicatedBagCreate a new predicated bag filled with the accepted elements.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. - Returns:
- a new predicated bag.
 
- 
createPredicatedBagDecorates the given bag with validating behavior using the predicate. All accepted elements are appended to the bag. If the bag already contains elements, they are validated.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. - Parameters:
- bag- the bag to decorate, must not be null
- Returns:
- the decorated bag.
- Throws:
- NullPointerException- if bag is null
- IllegalArgumentException- if bag contains invalid elements
 
- 
createPredicatedListCreate a new predicated list filled with the accepted elements.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. - Returns:
- a new predicated list.
 
- 
createPredicatedListDecorates the given list with validating behavior using the predicate. All accepted elements are appended to the list. If the list already contains elements, they are validated.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. - Parameters:
- list- the List to decorate, must not be null
- Returns:
- the decorated list.
- Throws:
- NullPointerException- if list is null
- IllegalArgumentException- if list contains invalid elements
 
- 
createPredicatedMultiSetCreate a new predicated multiset filled with the accepted elements.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. - Returns:
- a new predicated multiset.
 
- 
createPredicatedMultiSetDecorates the given multiset with validating behavior using the predicate. All accepted elements are appended to the multiset. If the multiset already contains elements, they are validated.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. - Parameters:
- multiset- the multiset to decorate, must not be null
- Returns:
- the decorated multiset.
- Throws:
- NullPointerException- if multiset is null
- IllegalArgumentException- if multiset contains invalid elements
 
- 
createPredicatedQueueCreate a new predicated queue filled with the accepted elements.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. - Returns:
- a new predicated queue.
 
- 
createPredicatedQueueDecorates the given queue with validating behavior using the predicate. All accepted elements are appended to the queue. If the queue already contains elements, they are validated.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. - Parameters:
- queue- the queue to decorate, must not be null
- Returns:
- the decorated queue.
- Throws:
- NullPointerException- if queue is null
- IllegalArgumentException- if queue contains invalid elements
 
- 
createPredicatedSetCreate a new predicated set filled with the accepted elements.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. - Returns:
- a new predicated set.
 
- 
createPredicatedSetDecorates the given list with validating behavior using the predicate. All accepted elements are appended to the set. If the set already contains elements, they are validated.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. - Parameters:
- set- the set to decorate, must not be null
- Returns:
- the decorated set.
- Throws:
- NullPointerException- if set is null
- IllegalArgumentException- if set contains invalid elements
 
- 
rejectedElementsReturns an unmodifiable collection containing all rejected elements.- Returns:
- an unmodifiable collection
 
 
-