1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.functor.core;
18  
19  import java.io.Serializable;
20  
21  import org.apache.commons.functor.BinaryProcedure;
22  import org.apache.commons.functor.Procedure;
23  import org.apache.commons.functor.UnaryProcedure;
24  
25  /**
26   * A procedure that does nothing at all.
27   * <p>
28   * Note that this class implements {@link Procedure},
29   * {@link UnaryProcedure}, and {@link BinaryProcedure}.
30   * </p>
31   * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
32   */
33  public final class NoOp implements Procedure, UnaryProcedure<Object>, BinaryProcedure<Object, Object>, Serializable {
34      // static attributes
35      // ------------------------------------------------------------------------
36      /**
37       * Basic NoOp instance.
38       */
39      public static final NoOp INSTANCE = new NoOp();
40      /**
41       * serialVersionUID declaration.
42       */
43      private static final long serialVersionUID = 3768926349922273291L;
44  
45      // constructor
46      // ------------------------------------------------------------------------
47      /**
48       * Create a new NoOp.
49       */
50      public NoOp() {
51      }
52  
53      // predicate interface
54      // ------------------------------------------------------------------------
55      /**
56       * {@inheritDoc}
57       */
58      public void run() {
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      public void run(Object obj) {
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      public void run(Object left, Object right) {
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public boolean equals(Object that) {
78          return (that instanceof NoOp);
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      @Override
85      public int hashCode() {
86          return "NoOp".hashCode();
87      }
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public String toString() {
94          return "NoOp";
95      }
96  
97      // static methods
98      // ------------------------------------------------------------------------
99      /**
100      * Get a NoOp instance.
101      * @return NoOp
102      */
103     public static NoOp instance() {
104         return INSTANCE;
105     }
106 
107     /**
108      * Get a typed NoOp {@link UnaryProcedure}.
109      * @param <A> type
110      * @return <code>UnaryProcedure&lt;A&gt;</code>
111      */
112     @SuppressWarnings("unchecked")
113     public static <A> UnaryProcedure<A> unaryInstance() {
114         return (UnaryProcedure<A>) INSTANCE;
115     }
116 
117     /**
118      * Get a typed NoOp {@link BinaryProcedure}.
119      * @param <L> left type
120      * @param <R> right type
121      * @return <code>BinaryProcedure&lt;L, R&gt;</code>
122      */
123     @SuppressWarnings("unchecked")
124     public static <L, R> BinaryProcedure<L, R> binaryInstance() {
125         return (BinaryProcedure<L, R>) INSTANCE;
126     }
127 }