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 */
017package org.apache.commons.functor.core;
018
019import org.apache.commons.functor.BinaryFunction;
020import org.apache.commons.functor.BinaryPredicate;
021import org.apache.commons.functor.adapter.BinaryFunctionBinaryPredicate;
022import 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: 1345136 $ $Date: 2012-06-01 14:47:06 +0200 (Fr, 01 Jun 2012) $
029 */
030public final class LeftIdentity {
031
032    // static attributes
033    // ------------------------------------------------------------------------
034    /**
035     * Left-identity function.
036     */
037    public static final BinaryFunction<Object, Object, Object> FUNCTION = LeftIdentity.<Object, Object>function();
038
039    /**
040     * Left-identity predicate.
041     */
042    public static final BinaryPredicate<Boolean, Object> PREDICATE = LeftIdentity.<Object>predicate();
043
044    // constructor
045    // ------------------------------------------------------------------------
046    /**
047     * Create a new LeftIdentity (for clients that require an object).
048     */
049    public LeftIdentity() {
050    }
051
052    // static methods
053    // ------------------------------------------------------------------------
054
055    /**
056     * Get a Left-identity BinaryFunction.
057     * @param <L> the left argument type.
058     * @param <R> the right argument type.
059     * @return BinaryFunction<L, R, L>
060     */
061    public static <L, R> BinaryFunction<L, R, L> function() {
062        return IgnoreRightFunction.adapt(new Identity<L>());
063    }
064
065    /**
066     * Get a left-identity BinaryPredicate.
067     * @param <R> the right argument type.
068     * @return BinaryPredicate<Boolean, R>
069     */
070    public static <R> BinaryPredicate<Boolean, R> predicate() {
071        return BinaryFunctionBinaryPredicate.adapt(IgnoreRightFunction
072                .<Boolean, R, Boolean> adapt(new Identity<Boolean>()));
073    }
074}