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 org.apache.commons.functor.BinaryFunction;
20 import org.apache.commons.functor.BinaryPredicate;
21 import org.apache.commons.functor.adapter.BinaryFunctionBinaryPredicate;
22 import org.apache.commons.functor.adapter.IgnoreRightFunction;
23
24 /**
25 * Holder class for a left-identity <code>BinaryFunction</code> (evaluates to the left argument) and a left-identity
26 * <code>BinaryPredicate</code> (tests whether left <code>Boolean</code> argument equals <code>Boolean.TRUE</code>).
27 *
28 * @version $Revision: 1160411 $ $Date: 2011-08-22 22:09:01 +0200 (Mon, 22 Aug 2011) $
29 * @author Rodney Waldhoff
30 * @author Matt Benson
31 */
32 public final class LeftIdentity {
33
34 // static attributes
35 // ------------------------------------------------------------------------
36 /**
37 * Left-identity function.
38 */
39 public static final BinaryFunction<Object, Object, Object> FUNCTION = LeftIdentity.<Object, Object>function();
40
41 /**
42 * Left-identity predicate.
43 */
44 public static final BinaryPredicate<Boolean, Object> PREDICATE = LeftIdentity.<Object>predicate();
45
46 // constructor
47 // ------------------------------------------------------------------------
48 /**
49 * Create a new LeftIdentity (for clients that require an object).
50 */
51 public LeftIdentity() {
52 }
53
54 // static methods
55 // ------------------------------------------------------------------------
56
57 /**
58 * Get a Left-identity BinaryFunction.
59 * @param <L> the left argument type.
60 * @param <R> the right argument type.
61 * @return BinaryFunction<L, R, L>
62 */
63 public static <L, R> BinaryFunction<L, R, L> function() {
64 return IgnoreRightFunction.adapt(new Identity<L>());
65 }
66
67 /**
68 * Get a left-identity BinaryPredicate.
69 * @param <R> the right argument type.
70 * @return BinaryPredicate<Boolean, R>
71 */
72 public static <R> BinaryPredicate<Boolean, R> predicate() {
73 return BinaryFunctionBinaryPredicate.adapt(IgnoreRightFunction
74 .<Boolean, R, Boolean> adapt(new Identity<Boolean>()));
75 }
76 }