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.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: 1160415 $ $Date: 2011-08-22 22:14:38 +0200 (Mon, 22 Aug 2011) $ 029 * @author Rodney Waldhoff 030 * @author Matt Benson 031 */ 032 public final class RightIdentity { 033 034 // static attributes 035 // ------------------------------------------------------------------------ 036 /** 037 * Right-identity function. 038 */ 039 public static final BinaryFunction<Object, Object, Object> FUNCTION = RightIdentity.<Object, Object>function(); 040 041 /** 042 * Right-identity predicate. 043 */ 044 public static final BinaryPredicate<Object, Boolean> PREDICATE = 045 BinaryFunctionBinaryPredicate.adapt(IgnoreLeftFunction.adapt(new Identity<Boolean>())); 046 047 // constructor 048 // ------------------------------------------------------------------------ 049 /** 050 * Create a new RightIdentity. 051 */ 052 public RightIdentity() { 053 } 054 055 // static methods 056 // ------------------------------------------------------------------------ 057 058 /** 059 * Get a typed right-identity BinaryFunction. 060 * @param <L> the left argument type. 061 * @param <R> the right argument type. 062 * @return BinaryFunction<L, R, R> 063 */ 064 public static <L, R> BinaryFunction<L, R, R> function() { 065 return IgnoreLeftFunction.adapt(new Identity<R>()); 066 } 067 068 /** 069 * Get a typed right-identity BinaryPredicate. 070 * @param <L> the left argument type. 071 * @return BinaryPredicate<L, Boolean> 072 */ 073 public static <L> BinaryPredicate<L, Boolean> predicate() { 074 return BinaryFunctionBinaryPredicate.adapt( 075 IgnoreLeftFunction.<L, Boolean, Boolean>adapt(new Identity<Boolean>())); 076 } 077 }