All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.staccatocommons.lang.function.AbstractFunction3 Maven / Gradle / Ivy

/*
 Copyright (c) 2011, The Staccato-Commons Team

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation; version 3 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.
 */
package net.sf.staccatocommons.lang.function;

import net.sf.staccatocommons.defs.function.Function;
import net.sf.staccatocommons.defs.function.Function2;
import net.sf.staccatocommons.defs.function.Function3;
import net.sf.staccatocommons.defs.tuple.Tuple3;

/**
 * A three-arguments function
 * 
 * @author flbulgarelli
 * 
 * @param 
 *          function first argument type
 * @param 
 *          function second argument type
 * @param 
 *          function third argument type
 * @param 
 *          function return type
 * 
 * @see AbstractFunction
 */
public abstract class AbstractFunction3 extends AbstractDelayable3 implements
  Function3 {

  public final Function3 nullSafe() {
    return new AbstractFunction3() {
      public D apply(A arg0, B arg1, C arg2) {
        if (arg0 == null || arg1 == null || arg2 == null)
          return null;
        return AbstractFunction3.this.apply(arg0, arg1, arg2);
      }
    };
  }

  public Function apply(final A arg0, final B arg1) {
    return new AbstractFunction() {
      public D apply(C arg3) {
        return AbstractFunction3.this.apply(arg0, arg1, arg3);
      }
    };
  }

  public Function2 apply(final A arg0) {
    return new AbstractFunction2() {
      public D apply(B arg1, C arg2) {
        return AbstractFunction3.this.apply(arg0, arg1, arg2);
      }
    };
  }
  
  public Function, D> uncurry() {
    return new AbstractFunction, D>() {
      public D apply(Tuple3 argument) {
        return AbstractFunction3.this.apply(argument.first(), argument.second(), argument.third());
      }
    };
  }

  public String toString() {
    return "Function3";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy