import classifier.gp.*; /** * Defines the function AND bitwise * * @author Sacchi Matteo, Sassi Federico * @version 0.1 */ public class FunctionAND extends Function{ /** * inizialize an array of two gprogram containg other functions or terminals * */ public FunctionAND() { arg = new GProgram[2]; } /** * To get the name of the function of the node * @return AND */ public String getName() { return "AND"; } /** * Evaluate the program under the node passing an object with AND * @param input the object to evaluale Long or Integer * @return the result of the evaluation as an object */ public Object eval(Object input) { Object value1 = null; Object value2 = null; try { if (!(LongBox.class.isInstance(input) || LongBoxExt.class.isInstance(input))) { throw new IllegalArgumentException(); } value1 = arg[0].eval(input); value2 = arg[1].eval(input); if (value1.getClass() != value2.getClass()) { throw new IllegalArgumentException(); } } catch(Exception e) { e.printStackTrace(System.err); System.exit(-1); } if(value1.getClass() == LongBoxExt.class) { ((LongBoxExt) value1).longs[0] = ((LongBoxExt) value1).longs[0] & ((LongBoxExt) value2).longs[0]; return value1; } if(value1.getClass() == LongBox.class) { ((LongBox) value1).long_value = ((LongBox)value1).long_value & ((LongBox)value2).long_value; return value1; } return null; } public long eval(long x) { return arg[0].eval(x) & arg[1].eval(x); } public double eval(double i) { return 0.0; } public char[] eval(char[] string) { return new String("prova").toCharArray(); } }