001package com.hfg.util; 002 003import java.util.Objects; 004import java.util.function.Function; 005 006 007//------------------------------------------------------------------------------ 008/** 009 * Represents a function that accepts three arguments and produces a result. 010 * This is the three-arity specialization of {@link Function}. 011 * 012 * <p>This is a <a href="package-summary.html">functional interface</a> 013 * whose functional method is {@link #apply(Object, Object, Object)}. 014 * 015 * @param <A> the type of the first argument to the function 016 * @param <B> the type of the second argument to the function 017 * @param <C> the type of the third argument to the function 018 * @param <R> the type of the result of the function 019 * 020 <div> 021 @author J. Alex Taylor, hairyfatguy.com 022 </div> 023 */ 024//------------------------------------------------------------------------------ 025// com.hfg XML/HTML Coding Library 026// 027// This library is free software; you can redistribute it and/or 028// modify it under the terms of the GNU Lesser General Public 029// License as published by the Free Software Foundation; either 030// version 2.1 of the License, or (at your option) any later version. 031// 032// This library is distributed in the hope that it will be useful, 033// but WITHOUT ANY WARRANTY; without even the implied warranty of 034// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 035// Lesser General Public License for more details. 036// 037// You should have received a copy of the GNU Lesser General Public 038// License along with this library; if not, write to the Free Software 039// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 040// 041// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 042// jataylor@hairyfatguy.com 043//------------------------------------------------------------------------------ 044 045@FunctionalInterface 046public interface TriFunction<A, B, C, R> 047{ 048 /** 049 * Applies this function to the given arguments. 050 * 051 * @param a the first function argument 052 * @param b the second function argument 053 * @param c the third function argument 054 * @return the function result 055 */ 056 R apply(A a, B b, C c); 057 058 /** 059 * Returns a composed function that first applies this function to 060 * its input, and then applies the {@code after} function to the result. 061 * If evaluation of either function throws an exception, it is relayed to 062 * the caller of the composed function. 063 * 064 * @param <V> the type of output of the {@code after} function, and of the 065 * composed function 066 * @param after the function to apply after this function is applied 067 * @return a composed function that first applies this function and then 068 * applies the {@code after} function 069 * @throws NullPointerException if after is null 070 */ 071 default <V> TriFunction<A, B, C, V> andThen(Function<? super R, ? extends V> after) 072 { 073 Objects.requireNonNull(after); 074 return (A a, B b, C c) -> after.apply(apply(a, b, c)); 075 } 076}