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.transformer;
17  
18  import net.sf.collections15.Transformer;
19  import net.sf.collections15.functors.FunctorException;
20  
21  import java.io.Serializable;
22  
23  /***
24   * <code>Transformer</code> implementation that always throws an exception.
25   *
26   * @author Stephen Colebourne
27   * @author Chris Lambrou (port to Java 5.0)
28   * @since Collections15 1.0
29   */
30  public final class ExceptionTransformer <I, O> implements Transformer<I, O>, Serializable
31  {
32  
33      static final long serialVersionUID = -1958843785134590867L;
34  
35      /***
36       * Returns an instance whose {@link #transform} method always throws an
37       * exception.
38       *
39       * @return An instance whose {@link #transform} method always throws an
40       *         exception.
41       *
42       * @since Collections15 1.0
43       */
44      public static <I, O> ExceptionTransformer<I, O> getInstance()
45      {
46          return new ExceptionTransformer<I, O>();
47      }
48  
49      /***
50       * Creates a new instance whose {@link #transform} method always throws an
51       * exception.
52       */
53      protected ExceptionTransformer()
54      {
55      }
56  
57      /***
58       * Transforms the input by ignoring it and throwing an exception instead.
59       *
60       * @param input The input object which is ignored.
61       *
62       * @return This method never returns.
63       *
64       * @throws FunctorException Always thrown by this method.
65       */
66      public O transform(I input) throws FunctorException
67      {
68          throw new FunctorException("ExceptionTransformer invoked");
69      }
70  
71  }