package org.syrup.functions;
import org.syrup.Context;
import org.syrup.Data;
import org.syrup.Function;
import org.syrup.Result;
import org.syrup.helpers.ResultImpl;
import org.syrup.helpers.Utils;
import java.util.logging.Logger;
/**
* Duplicates either the first or second input to both first and second output.
* If both first and second input are filled, it will copy the first input to
* the first output and leaves the second input. The next round will copy the
* second input if the first input isn't filled.
*
* @author Robbert van Dalen
*/
public class Duplicate implements Function
{
static final String COPYRIGHT = "Copyright 2005 Robbert van Dalen."
+ "At your option, you may copy, distribute, or make derivative works under "
+ "the terms of The Artistic License. This License may be found at "
+ "http://www.opensource.org/licenses/artistic-license.php. "
+ "THERE IS NO WARRANTY; USE THIS PRODUCT AT YOUR OWN RISK.";
private final static Logger logger = Logger.getLogger("org.syrup.functions.Duplicate");
/**
*/
public Result execute(Context context)
{
Data out = null;
try
{
if (Utils.isFull(context.in_1_link())
&& Utils.isFull(context.in_2_link()))
{
out = context.in_1_link().content();
return new ResultImpl(context, true, false, out, out);
}
else
{
if (Utils.isFull(context.in_2_link()))
{
out = context.in_2_link().content();
}
else
{
out = context.in_1_link().content();
}
}
return new ResultImpl(context, true, true, out, out);
}
catch (Throwable e1)
{
// Something is *very* wrong.
return new ResultImpl(context, true, true, null, org.syrup.helpers.Utils.manageError(logger, e1, "Concat error"));
}
}
}