View Javadoc

1   package net.sf.collections15.functors.predicate;
2   
3   import net.sf.collections15.Predicate;
4   import net.sf.collections15.PredicateDecorator;
5   
6   import java.io.Serializable;
7   
8   /***
9    * Abstract implementation of a <code>Predicate</code> that decorates another
10   * <code>Predicate</code> instance.
11   * <p/>
12   * Note that the generic type of the decorated <code>Predicate</code>,
13   * <code>D</code>, and the generic type of the decorating
14   * <code>Predicate</code>, <code>E</code> are not necessarily the same.
15   *
16   * @author Chris Lambrou
17   * @since Collections15 1.0
18   */
19  public abstract class AbstractPredicateDecorator <E> implements PredicateDecorator<E>, Predicate<E>, Serializable
20  {
21      static final long serialVersionUID = -1458209148826550025L;
22  
23      /***
24       * The decorated <code>Predicate</code>. Sub-classes may modify this
25       * reference, but it should not be set to <code>null</code> as {@link
26       * #getDecoratedPredicate} references this field.
27       */
28      protected Predicate<? super E> decoratedPredicate;
29  
30      /***
31       * Creates a new instance. Performs checking to detect whether or not the
32       * specified <code>Predicate</code> is <code>null</code>, so sub-classes
33       * needn't perform this check.
34       *
35       * @param decoratedPredicate The decorated <code>Predicate</code>.
36       *
37       * @throws IllegalArgumentException Thrown if the specified <code>Predicate</code>
38       *                                  to decorate is <code>null</code>.
39       */
40      protected AbstractPredicateDecorator(Predicate<? super E> decoratedPredicate)
41      {
42          if (decoratedPredicate == null) {
43              throw new IllegalArgumentException("decoratedPredicate cannot be null");
44          }
45          this.decoratedPredicate = decoratedPredicate;
46      }
47  
48      /***
49       * Returns the <code>Predicate</code> decorated by this
50       * <code>Predicate</code>.
51       *
52       * @return The decorated <code>Predicate</code>.
53       */
54      public Predicate<? super E> getDecoratedPredicate()
55      {
56          return decoratedPredicate;
57      }
58  }