/*
 * #%L
 * ImageJ OPS: a framework for reusable algorithms.
 * %%
 * Copyright (C) 2014 Board of Regents of the University of
 * Wisconsin-Madison and University of Konstanz.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * #L%
 */

package net.imagej.ops;

/**
 * Abstract superclass for a {@link OutputFunction} which is capable creating an
 * output object.
 * 
 * @author Christian Dietz (University of Konstanz)
 */
public abstract class AbstractOutputFunction<I, O> extends
		AbstractFunction<I, O> implements OutputFunction<I, O> {

	@Override
	public void run() {
		if (getOutput() == null) {
			setOutput(compute(getInput()));
		} else {
			setOutput(compute(getInput(), getOutput()));
		}
	}

	@Override
	public O compute(final I input) {
		return compute(input, createOutput(input));
	}
}

@@ -1677,16 +1677,41 @@
 nstanz)%0A
+ * @author Curtis Rueden%0A
  */%0Apubl
@@ -1848,147 +1848,80 @@
 lic 
-void run() %7B%0A%09%09if (getOutput() == null) %7B%0A%09%09%09setOutput(compute(getInput()));%0A%09%09%7D else %7B%0A%09%09%09setOutput(compute(getInput(), getOutput()));%0A%09%09%7D
+O compute(final I input) %7B%0A%09%09return compute(input, createOutput(input));
 %0A%09%7D%0A
@@ -1955,32 +1955,48 @@
 te(final I input
+, final O output
 ) %7B%0A%09%09return com
@@ -1984,33 +1984,37 @@
 put) %7B%0A%09%09return 
-c
+safeC
 ompute(input, cr
@@ -2002,32 +2002,49 @@
 feCompute(input,
+ output == null ?
  createOutput(in
@@ -2047,16 +2047,288 @@
 t(input)
+ : output);%0A%09%7D%0A%0A%09// -- Internal methods --%0A%0A%09/**%0A%09 * Does the work of computing the function.%0A%09 * %0A%09 * @param input Non-null input value.%0A%09 * @param output Non-null output value.%0A%09 * @return The computed output value.%0A%09 */%0A%09protected abstract O safeCompute(I input, O output
 );%0A
-%09%7D
 %0A%7D%0A

check for null output