001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.functor.core; 018 019 import java.io.Serializable; 020 021 import org.apache.commons.functor.BinaryProcedure; 022 import org.apache.commons.functor.Procedure; 023 import org.apache.commons.functor.UnaryProcedure; 024 025 /** 026 * A procedure that does nothing at all. 027 * <p> 028 * Note that this class implements {@link Procedure}, 029 * {@link UnaryProcedure}, and {@link BinaryProcedure}. 030 * </p> 031 * @version $Revision: 1156349 $ $Date: 2011-08-10 22:21:14 +0200 (Wed, 10 Aug 2011) $ 032 * @author Rodney Waldhoff 033 */ 034 public final class NoOp implements Procedure, UnaryProcedure<Object>, BinaryProcedure<Object, Object>, Serializable { 035 // static attributes 036 // ------------------------------------------------------------------------ 037 /** 038 * Basic NoOp instance. 039 */ 040 public static final NoOp INSTANCE = new NoOp(); 041 /** 042 * serialVersionUID declaration. 043 */ 044 private static final long serialVersionUID = 3768926349922273291L; 045 046 // constructor 047 // ------------------------------------------------------------------------ 048 /** 049 * Create a new NoOp. 050 */ 051 public NoOp() { 052 } 053 054 // predicate interface 055 // ------------------------------------------------------------------------ 056 /** 057 * {@inheritDoc} 058 */ 059 public void run() { 060 } 061 062 /** 063 * {@inheritDoc} 064 */ 065 public void run(Object obj) { 066 } 067 068 /** 069 * {@inheritDoc} 070 */ 071 public void run(Object left, Object right) { 072 } 073 074 /** 075 * {@inheritDoc} 076 */ 077 public boolean equals(Object that) { 078 return (that instanceof NoOp); 079 } 080 081 /** 082 * {@inheritDoc} 083 */ 084 public int hashCode() { 085 return "NoOp".hashCode(); 086 } 087 088 /** 089 * {@inheritDoc} 090 */ 091 public String toString() { 092 return "NoOp"; 093 } 094 095 // static methods 096 // ------------------------------------------------------------------------ 097 /** 098 * Get a NoOp instance. 099 * @return NoOp 100 */ 101 public static NoOp instance() { 102 return INSTANCE; 103 } 104 105 /** 106 * Get a typed NoOp {@link UnaryProcedure}. 107 * @param <A> type 108 * @return <code>UnaryProcedure<A></code> 109 */ 110 @SuppressWarnings("unchecked") 111 public static <A> UnaryProcedure<A> unaryInstance() { 112 return (UnaryProcedure<A>) INSTANCE; 113 } 114 115 /** 116 * Get a typed NoOp {@link BinaryProcedure}. 117 * @param <L> left type 118 * @param <R> right type 119 * @return <code>BinaryProcedure<L, R></code> 120 */ 121 @SuppressWarnings("unchecked") 122 public static <L, R> BinaryProcedure<L, R> binaryInstance() { 123 return (BinaryProcedure<L, R>) INSTANCE; 124 } 125 }