1 package net.sf.collections15.functors.predicate; 2 3 import net.sf.collections15.MultplePredicateDecorator; 4 import net.sf.collections15.Predicate; 5 6 import java.io.Serializable; 7 import java.util.ArrayList; 8 import java.util.Collection; 9 import java.util.Collections; 10 import java.util.List; 11 12 /*** 13 * Abstract implementation of a <code>Predicate</code> that decorates multiple 14 * <code>Predicate</code> instances. 15 * 16 * @author Chris Lambrou 17 * @since Collections15 1.0 18 */ 19 public abstract class AbstractMultplePredicateDecorator <E> implements MultplePredicateDecorator<E>, Predicate<E>, Serializable 20 { 21 static final long serialVersionUID = -4510894808298473842L; 22 23 /*** 24 * The decorated <code>Predicate</code>s, sub-classes may modify or replace 25 * this list, but it should not be set to <code>null</code> as {@link 26 * #getDecoratedPredicates} references this field. 27 */ 28 protected List<Predicate<? super E>> decoratedPredicates; 29 30 /*** 31 * Creates a new instance. Performs checking to detect whether or not the 32 * specified <code>Predicate</code> collection is valid, so sub-classes 33 * needn't perform this check. 34 * 35 * @param decoratedPredicates A collection of the decorated <code>Predicate</code>s. 36 * 37 * @throws IllegalArgumentException Thrown if the specified collection is 38 * <code>null</code> or contains 39 * <code>null</code> elements. The 40 * collection may be empty, however. 41 */ 42 protected AbstractMultplePredicateDecorator(Collection<Predicate<? super E>> decoratedPredicates) 43 { 44 if (decoratedPredicates == null) { 45 throw new IllegalArgumentException("decoratedPredicate cannot be null"); 46 } 47 this.decoratedPredicates = new ArrayList<Predicate<? super E>>(decoratedPredicates.size()); 48 for (Predicate<? super E> predicate : decoratedPredicates) { 49 if (predicate == null) { 50 throw new IllegalArgumentException("null predicates in the specified collection not allowed"); 51 } 52 this.decoratedPredicates.add(predicate); 53 } 54 } 55 56 /*** 57 * Returns a list of the <code>Predicate</code>s decorated by this 58 * <code>Predicate</code>. 59 * 60 * @return A list of the decorated <code>Predicate</code>s. The returned 61 * list is unmodifiable. 62 */ 63 public List<Predicate<? super E>> getDecoratedPredicates() 64 { 65 return Collections.unmodifiableList(decoratedPredicates); 66 } 67 }