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

net.sf.staccatocommons.lang.function.AbstractDelayable2 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.Applicable2;
import net.sf.staccatocommons.defs.Delayable2;
import net.sf.staccatocommons.defs.Thunk;
import net.sf.staccatocommons.restrictions.check.NonNull;

/**
 * @author flbulgarelli
 * 
 * @param 
 * @param 
 * @param 
 */
public abstract class AbstractDelayable2 implements Applicable2, Delayable2 {

  /**
   * Creates a new {@link AbstractDelayable2}
   */
  public AbstractDelayable2() {
    super();
  }

  /**
   * Delays execution of this block by returning a void thunk that will evaluate
   * exec(arg1, arg2) each time its value is required
   * 
   * @param arg0
   * @param arg1
   * @return a new void {@link Thunk}
   */
  public Thunk delayed(final A arg0, final B arg1) {
    return new Thunk() {
      public C value() {
        return apply(arg0, arg1);
      }
    };
  }

  @NonNull
  @Override
  public Thunk delayedValue(@NonNull final Thunk thunk0, @NonNull final Thunk thunk1) {
    return new Thunk() {
      public C value() {
        return apply(thunk0.value(), thunk1.value());
      }
    };
  }

}