package jcgp.function; import jcgp.exceptions.InvalidArgumentsException; import jcgp.population.Connection; public class Multiplication extends Function { private int arity = 2; @Override public Object run(Connection... connections) { if (connections.length < arity) { throw new InvalidArgumentsException("Not enough connections were given."); } else if (connections[0].getValue() instanceof Integer) { Integer arg1 = ((Integer) connections[0].getValue()); Integer arg2 = ((Integer) connections[1].getValue()); Integer result = arg1 * arg2; System.out.println(arg1 + " * " + arg2 + " = " + result); return result; } else { throw new InvalidArgumentsException("Wrong data type, this function takes Integer."); } } @Override public int getArity() { return arity; } }