View Javadoc

1   /*
2    *  Copyright 2001-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package net.sf.collections15.functors.predicate;
17  
18  import net.sf.collections15.Predicate;
19  
20  import java.io.Serializable;
21  
22  
23  /***
24   * <code>Predicate</code> implementation that only returns <code>true</code> if
25   * the input is <code>null</code>.
26   *
27   * @author Stephen Colebourne
28   * @author Chris Lambrou (port to Java 5.0)
29   * @since Collections15 1.0
30   */
31  public final class NullPredicate <E> implements Predicate<E>, Serializable
32  {
33  
34      static final long serialVersionUID = -7530319632197704941L;
35  
36      /***
37       * Returns a <code>Predicate</code> that evaluates to <code>true</code> only
38       * if the input is <code>null</code>.
39       *
40       * @return A <code>Predicate</code> that evaluates to <code>true</code> only
41       *         if the input is <code>null</code>.
42       *
43       * @since Collections15 1.0
44       */
45      public static <T> NullPredicate<T> getInstance()
46      {
47          return new NullPredicate<T>();
48      }
49  
50      /***
51       * creates a new instance.
52       */
53      protected NullPredicate()
54      {
55      }
56  
57      /***
58       * Evaluates the <code>Predicate</code> returning <code>true</code> only if
59       * the input is <code>null</code>.
60       *
61       * @param object The input object to evaluate.
62       *
63       * @return <code>true</code> if the input is <code>null</code>.
64       */
65      public boolean evaluate(E object)
66      {
67          return (object == null);
68      }
69  
70  }