From: Matt I. <mat...@us...> - 2004-09-17 20:00:56
|
Update of /cvsroot/ant-contrib/ant-contrib/src/net/sf/antcontrib/math In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9966 Modified Files: MathTask.java Operation.java Log Message: Allow dynamic elements such as <add> and <sin> instead of <op op="add" ... /> Index: MathTask.java =================================================================== RCS file: /cvsroot/ant-contrib/ant-contrib/src/net/sf/antcontrib/math/MathTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MathTask.java 15 Sep 2004 21:47:29 -0000 1.2 --- MathTask.java 17 Sep 2004 20:00:47 -0000 1.3 *************** *** 18,21 **** --- 18,22 ---- import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; + import org.apache.tools.ant.DynamicElement; /** *************** *** 28,31 **** --- 29,33 ---- public class MathTask extends Task + implements DynamicElement { // storage for result *************** *** 55,58 **** --- 57,68 ---- } + public Object createDynamicElement(String name) + throws BuildException { + Operation op = new Operation(); + op.setOperation(name); + operation = op; + return op; + } + public void setResult(String result) { Index: Operation.java =================================================================== RCS file: /cvsroot/ant-contrib/ant-contrib/src/net/sf/antcontrib/math/Operation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Operation.java 23 Aug 2004 22:42:49 -0000 1.1 --- Operation.java 17 Sep 2004 20:00:47 -0000 1.2 *************** *** 16,20 **** --- 16,26 ---- package net.sf.antcontrib.math; + import org.apache.tools.ant.BuildException; + import org.apache.tools.ant.DynamicElement; + import java.util.Vector; + import java.util.List; + import java.util.ArrayList; + import java.util.Arrays; /** *************** *** 26,31 **** public class Operation ! implements Evaluateable ! { private String operation = "add"; private Vector operands = new Vector(); --- 32,36 ---- public class Operation ! implements Evaluateable, DynamicElement { private String operation = "add"; private Vector operands = new Vector(); *************** *** 33,63 **** private boolean strict = false; ! public void addConfiguredNumeric(Numeric numeric) ! { operands.add(numeric); } ! public void addConfiguredOperation(Operation operation) ! { operands.add(operation); } ! public void addConfiguredNum(Numeric numeric) ! { operands.add(numeric); } ! public void addConfiguredOp(Operation operation) ! { operands.add(operation); } ! public void setOp(String operation) ! { setOperation(operation); } ! public void setOperation(String operation) ! { if (operation.equals("+")) this.operation = "add"; --- 38,111 ---- private boolean strict = false; ! private boolean hasLocalOperands = false; ! private Numeric localOperands[] = new Numeric[5]; ! ! public Object createDynamicElement(String name) ! throws BuildException { ! Operation op = new Operation(); ! op.setOperation(name); ! operands.add(op); ! return op; ! } ! ! private void setLocalOperand(String value, int index) { ! hasLocalOperands = true; ! localOperands[index - 1] = new Numeric(); ! localOperands[index - 1].setValue(value); ! } ! ! public void setArg1(String value) { ! setLocalOperand(value, 1); ! } ! ! public void setArg2(String value) { ! setLocalOperand(value, 2); ! } ! ! public void setArg3(String value) { ! setLocalOperand(value, 3); ! } ! ! public void setArg4(String value) { ! setLocalOperand(value, 4); ! } ! ! public void setArg5(String value) { ! setLocalOperand(value, 5); ! } ! ! public void addConfiguredNumeric(Numeric numeric) { ! if (hasLocalOperands) ! throw new BuildException("Cannot combine operand attributes with subelements"); ! operands.add(numeric); } ! public void addConfiguredOperation(Operation operation) { ! if (hasLocalOperands) ! throw new BuildException("Cannot combine operand attributes with subelements"); ! operands.add(operation); } ! public void addConfiguredNum(Numeric numeric) { ! if (hasLocalOperands) ! throw new BuildException("Cannot combine operand attributes with subelements"); ! operands.add(numeric); } ! public void addConfiguredOp(Operation operation) { ! if (hasLocalOperands) ! throw new BuildException("Cannot combine operand attributes with subelements"); ! operands.add(operation); } ! public void setOp(String operation) { setOperation(operation); } ! public void setOperation(String operation) { if (operation.equals("+")) this.operation = "add"; *************** *** 74,91 **** } ! public void setDatatype(String datatype) ! { this.datatype = datatype; } ! public void setStrict(boolean strict) ! { this.strict = strict; } ! public Number evaluate() ! { ! Evaluateable ops[] = ! (Evaluateable[]) operands.toArray(new Evaluateable[operands.size()]); return Math.evaluate(operation, --- 122,148 ---- } ! public void setDatatype(String datatype) { this.datatype = datatype; } ! public void setStrict(boolean strict) { this.strict = strict; } ! public Number evaluate() { ! Evaluateable ops[] = null; ! ! if (hasLocalOperands) { ! List localOps = new ArrayList(); ! for (int i = 0; i < localOperands.length; i++) { ! if (localOperands[i] != null) ! localOps.add(localOperands[i]); ! } ! ! ops = (Evaluateable[]) localOps.toArray(new Evaluateable[localOps.size()]); ! } ! else { ! ops = (Evaluateable[]) operands.toArray(new Evaluateable[operands.size()]); ! } return Math.evaluate(operation, *************** *** 95,103 **** } ! public String toString() ! { return "Operation[operation=" + operation + ";datatype=" + datatype + ";strict=" + strict + ";operands=" + operands + "]"; --- 152,160 ---- } ! public String toString() { return "Operation[operation=" + operation + ";datatype=" + datatype + ";strict=" + strict + + ";localoperands=" + Arrays.asList(localOperands) + ";operands=" + operands + "]"; |