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 org.apache.commons.functor.BinaryFunction;
020    import org.apache.commons.functor.BinaryPredicate;
021    import org.apache.commons.functor.adapter.BinaryFunctionBinaryPredicate;
022    import org.apache.commons.functor.adapter.IgnoreRightFunction;
023    
024    /**
025     * Holder class for a left-identity <code>BinaryFunction</code> (evaluates to the left argument) and a left-identity
026     * <code>BinaryPredicate</code> (tests whether left <code>Boolean</code> argument equals <code>Boolean.TRUE</code>).
027     *
028     * @version $Revision: 1160411 $ $Date: 2011-08-22 22:09:01 +0200 (Mon, 22 Aug 2011) $
029     * @author Rodney Waldhoff
030     * @author Matt Benson
031     */
032    public final class LeftIdentity {
033    
034        // static attributes
035        // ------------------------------------------------------------------------
036        /**
037         * Left-identity function.
038         */
039        public static final BinaryFunction<Object, Object, Object> FUNCTION = LeftIdentity.<Object, Object>function();
040    
041        /**
042         * Left-identity predicate.
043         */
044        public static final BinaryPredicate<Boolean, Object> PREDICATE = LeftIdentity.<Object>predicate();
045    
046        // constructor
047        // ------------------------------------------------------------------------
048        /**
049         * Create a new LeftIdentity (for clients that require an object).
050         */
051        public LeftIdentity() {
052        }
053    
054        // static methods
055        // ------------------------------------------------------------------------
056    
057        /**
058         * Get a Left-identity BinaryFunction.
059         * @param <L> the left argument type.
060         * @param <R> the right argument type.
061         * @return BinaryFunction<L, R, L>
062         */
063        public static <L, R> BinaryFunction<L, R, L> function() {
064            return IgnoreRightFunction.adapt(new Identity<L>());
065        }
066    
067        /**
068         * Get a left-identity BinaryPredicate.
069         * @param <R> the right argument type.
070         * @return BinaryPredicate<Boolean, R>
071         */
072        public static <R> BinaryPredicate<Boolean, R> predicate() {
073            return BinaryFunctionBinaryPredicate.adapt(IgnoreRightFunction
074                    .<Boolean, R, Boolean> adapt(new Identity<Boolean>()));
075        }
076    }