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.IgnoreLeftFunction;
023
024/**
025 * Holder class for a right-identity <code>BinaryFunction</code> (evaluates to the right argument) and a right-identity
026 * <code>BinaryPredicate</code> (tests whether right <code>Boolean</code> argument equals <code>Boolean.TRUE</code>).
027 *
028 * @version $Revision: 1364767 $ $Date: 2012-07-23 21:36:08 +0200 (Mo, 23 Jul 2012) $
029 */
030public final class RightIdentity {
031
032    // static attributes
033    // ------------------------------------------------------------------------
034    /**
035     * Right-identity function.
036     */
037    public static final BinaryFunction<Object, Object, Object> FUNCTION = RightIdentity.<Object, Object>function();
038
039    /**
040     * Right-identity predicate.
041     */
042    public static final BinaryPredicate<Object, Boolean> PREDICATE = RightIdentity.<Object>predicate();
043
044    // constructor
045    // ------------------------------------------------------------------------
046    /**
047     * Create a new RightIdentity.
048     */
049    public RightIdentity() {
050    }
051
052    // static methods
053    // ------------------------------------------------------------------------
054
055    /**
056     * Get a typed right-identity BinaryFunction.
057     * @param <L> the left argument type.
058     * @param <R> the right argument type.
059     * @return BinaryFunction<L, R, R>
060     */
061    public static <L, R> BinaryFunction<L, R, R> function() {
062        return IgnoreLeftFunction.adapt(new Identity<R>());
063    }
064
065    /**
066     * Get a typed right-identity BinaryPredicate.
067     * @param <L> the left argument type.
068     * @return BinaryPredicate<L, Boolean>
069     */
070    public static <L> BinaryPredicate<L, Boolean> predicate() {
071        return BinaryFunctionBinaryPredicate.adapt(
072                IgnoreLeftFunction.<L, Boolean, Boolean>adapt(new Identity<Boolean>()));
073    }
074}