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  import net.sf.collections15.functors.FunctorException;
20  
21  import java.io.Serializable;
22  
23  
24  /***
25   * <code>Predicate</code> implementation whose {@link #evaluate} method always
26   * throws an exception.
27   *
28   * @author Stephen Colebourne
29   * @author Chris Lambrou (port to Java 5.0)
30   * @since Collections15 1.0
31   */
32  public final class ExceptionPredicate <E> implements Predicate<E>, Serializable
33  {
34  
35      static final long serialVersionUID = -5997593482941374688L;
36  
37      /***
38       * Returns an instance of <code>ExceptionPredicate</code>.
39       *
40       * @return An instance of <code>ExceptionPredicate</code>.
41       *
42       * @since Collections 1.0
43       */
44      public static <T> ExceptionPredicate<T> getInstance()
45      {
46          return new ExceptionPredicate<T>();
47      }
48  
49      /***
50       * Creates a new instance.
51       */
52      protected ExceptionPredicate()
53      {
54      }
55  
56      /***
57       * Evaluates the <code>Predicate</code>, always throwing an exception.
58       *
59       * @param object The input object.
60       *
61       * @return This method always throws an exception.
62       *
63       * @throws FunctorException Always thrown by this <code>Predicate</code>.
64       */
65      public boolean evaluate(E object)
66      {
67          throw new FunctorException("ExceptionPredicate invoked with argument " + object);
68      }
69  
70  }