package edu.washington.escience.myriad.operator.apply;

import java.util.List;

/**
 * Constant multiplication Function for use in Apply.
 */

public final class ConstantMultiplicationIFunction extends IFunction {

  /** Required for Java serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * creates the Constant Multiplication function with the desired power value.
   */
  public ConstantMultiplicationIFunction() {
  }

  /**
   * {@inheritDoc}
   * 
   * @throws IllegalArgumentException , the wrong argument was passed
   */
  @Override
  public Number execute(final List<Number> source, final List<Number> arguments) {
    checkPreconditions(source, numApplyFields());
    checkPreconditions(arguments, numExtraArgument());
    Number src = source.get(0);
    Number constant = arguments.get(0);
    if (src instanceof Long) {
      return constant.longValue() * src.longValue();
    } else if (src instanceof Integer) {
      return constant.intValue() * src.intValue();
    } else {
      return constant.doubleValue() * src.doubleValue();
    }
  }

  @Override
  public String toString(final List<String> names, final List<Number> arguments) {
    checkPreconditions(arguments, numExtraArgument());
    checkPreconditions(names, numApplyFields());
    return arguments.get(0) + " * " + names.get(0);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int numApplyFields() {
    return 1;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int numExtraArgument() {
    return 1;
  }
}

@@ -1014,64 +1014,284 @@
 lse 
-%7B%0A      return constant.doubleValue() * src.doubleValue(
+if (src instanceof Float) %7B%0A      return constant.floatValue() * src.floatValue();%0A    %7D else if (src instanceof Double) %7B%0A      return constant.doubleValue() * src.doubleValue();%0A    %7D else %7B%0A      throw new IllegalArgumentException(%22Unexpected src of type %22 + src.getClass()
 );%0A 

make execute match its signature