Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /antelope/, /antelope/src/ise/antelope/common/, /antelope/src/ise/antelope/plugin/, /antelope/src/ise/antelope/tasks/, /antelope/src/ise/library/

antelope
Discussion topic

Back to topic list

CVS update: /antelope/, /antelope/src/ise/antelope/common/, /antelope/src/ise/antelope/plugin/, /antelope/src/ise/antelope/tasks/, /antelope/src/ise/library/

Author danson
Full name Dale Anson
Date 2004-09-25 20:40:34 PDT
Message User: danson Date: 04/09/25 20:40:34 Modified: /antelope/ build.props /antelope/src/ise/antelope/common/ version.txt /antelope/src/ise/antelope/plugin/ AntelopePlugin.java /antelope/src/ise/antelope/tasks/ Math.java, MathTask.java, Num.java, Op.java /antelope/src/ise/library/ PrivilegedAccessor.java Log: enum -> en, plus a fix in PrivilegedAccessor Issue number: Obtained from: Submitted by: Reviewed by: File Changes: Directory: /antelope/ ===================== File [changed]: build.props Url: http://antelope.tigris.org/source/browse/antelope/build.props?r1=1.22&r2=1.23 Delta lines: +7 -7 ------------------- --- build.props 30 Jul 2004 03:21:39 -0000 1.22 +++ build.props 26 Sep 2004 03:40:33 -0000 1.23 @@ -1,16 +1,16 @@ # required settings # linux: -#jedit.install.dir=${user.home}/apps/jedit/4.2pre8 -#docbook.xsl=file:///usr/share/sgml/docbook/xsl-stylesheets-1.60.1 -#docbookx.dtd=file:///usr/share/sgml/docbook/xml-dtd-4.1.2/docbookx.dtd +jedit.install.dir=${user.home}/apps/jedit/4.2pre13 +docbook.xsl=file:///usr/share/sgml/docbook/xsl-stylesheets-1.60.1 +docbookx.dtd=file:///usr/share/sgml/docbook/xml-dtd-4.1.2/docbookx.dtd # windows: -jedit.install.dir=c:/jEdit -docbook.xsl=file:///C:/cygwin/usr/share/docbook-xsl -docbookx.dtd=file:///C:/cygwin/usr/share/docbook-xml42/docbookx.dtd +#jedit.install.dir=c:/jEdit +#docbook.xsl=file:///C:/cygwin/usr/share/docbook-xsl +#docbookx.dtd=file:///C:/cygwin/usr/share/docbook-xml42/docbookx.dtd install.dir=${user.home}/.jedit/jars -build.num=3.1.9 +build.num=3.1.11 # optional settings, remove if you don't use jikes build.compiler=jikes Directory: /antelope/src/ise/antelope/common/ ============================================= File [changed]: version.txt Url: http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/common/version.txt?r1=1.34&r2=1.35 Delta lines: +2 -2 ------------------- --- version.txt 4 Sep 2004 03:52:16 -0000 1.34 +++ version.txt 26 Sep 2004 03:40:33 -0000 1.35 @@ -1,2 +1,2 @@ -VERSION=3.1.9 -DATE=August 29 2004 \ No newline at end of file +VERSION=3.1.11 +DATE=September 25 2004 \ No newline at end of file Directory: /antelope/src/ise/antelope/plugin/ ============================================= File [changed]: AntelopePlugin.java Url: http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/plugin/AntelopePlugin.java?r1=1.11&r2=1.12 Delta lines: +4 -4 ------------------- --- AntelopePlugin.java 6 Jun 2004 11:09:56 -0000 1.11 +++ AntelopePlugin.java 26 Sep 2004 03:40:34 -0000 1.12 @@ -1,4 +1,4 @@ -// $Id: AntelopePlugin.java,v 1.11 2004/06/06 11:09:56 danson Exp $ +// $Id: AntelopePlugin.java,v 1.12 2004/09/26 03:40:34 danson Exp $ /* * Based on the Apache Software License, Version 1.1 * @@ -73,7 +73,7 @@ /** * This is the AntelopePlugin. * - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ */ public class AntelopePlugin extends EBPlugin implements Constants { /** @@ -378,9 +378,9 @@ ProjectHelper.configureProject( project, buildFile ); Hashtable h = project.getTargets(); String[] targets = new String[ h.size() ]; - Enumeration enum = h.keys(); + Enumeration en = h.keys(); for ( int i = 0; i < targets.length; i++ ) { - targets[ i ] = ( String ) enum.nextElement(); + targets[ i ] = ( String ) en.nextElement(); } return targets; } Directory: /antelope/src/ise/antelope/tasks/ ============================================ File [changed]: Math.java Url: http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/tasks/Math.java?r1=1.2&r2=1.3 Delta lines: +473 -125 ----------------------- --- Math.java 4 Sep 2004 03:52:16 -0000 1.2 +++ Math.java 26 Sep 2004 03:40:34 -0000 1.3 @@ -1,60 +1,10 @@ -/* -* The Apache Software License, Version 1.1 -* -* Copyright (c) 2001-2002 The Apache Software Foundation. All rights -* reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* 3. The end-user documentation included with the redistribution, if -* any, must include the following acknowlegement: -* "This product includes software developed by the -* Apache Software Foundation (http://www.apache.org/)." -* Alternately, this acknowlegement may appear in the software itself, -* if and wherever such third-party acknowlegements normally appear. -* -* 4. The names "The Jakarta Project", "Ant", and "Apache Software -* Foundation" must not be used to endorse or promote products derived -* from this software without prior written permission. For written -* permission, please contact apache@apache.org. -* -* 5. Products derived from this software may not be called "Apache" -* nor may "Apache" appear in their names without prior written -* permission of the Apache Group. -* -* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR -* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -* ==================================================================== -* -* This software consists of voluntary contributions made by many -* individuals on behalf of the Apache Software Foundation. For more -* information on the Apache Software Foundation, please see -* . -*/ package ise.antelope.tasks; import java.lang.reflect.Method; import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.math.BigInteger; +import java.math.BigDecimal; import java.util.Vector; import java.util.Enumeration; @@ -62,12 +12,30 @@ * Provides access to java.lang.Math and java.lang.StrictMath for Ant. Provides * add, subtract, multiply, divide and mod methods as well as access to all methods * java.lang.Math and java.lang.StrictMath via reflection. + *

Copyright 2003, Dale Anson, all rights reserved * @author Dale Anson, danson@germane-software.com */ public class Math { private boolean strict = false; + public static Class BIGDECIMAL_TYPE; + public static Class BIGINT_TYPE; + static { + try { + BIGDECIMAL_TYPE = Class.forName( "java.math.BigDecimal" ); + } + catch ( ClassNotFoundException e ) { + BIGDECIMAL_TYPE = null; + } + try { + BIGINT_TYPE = Class.forName( "java.math.BigInteger" ); + } + catch ( Exception e ) { + BIGINT_TYPE = null; + } + } + public Math() {} public Math( boolean strict ) { @@ -82,6 +50,46 @@ return strict; } + public static BigDecimal add( BigDecimal a, BigDecimal b ) { + return a.add( b ); + } + + public static BigInteger add( BigInteger a, BigInteger b ) { + return a.add( b ); + } + + public static BigInteger and( BigInteger a, BigInteger b ) { + return a.and( b ); + } + + public static int and( int a, int b ) { + return a & b; + } + + public static BigInteger or( BigInteger a, BigInteger b ) { + return a.or( b ); + } + + public static int or( int a, int b ) { + return a | b; + } + + public static BigInteger not( BigInteger a ) { + return a.not(); + } + + public static int not( int a ) { + return ~a; + } + + public static BigInteger xor( BigInteger a, BigInteger b ) { + return a.xor( b ); + } + + public static int xor( int a, int b ) { + return a ^ b; + } + public static double add( double a, double b ) { return a + b; } @@ -94,6 +102,16 @@ public static int add( int a, int b ) { return a + b; } + public static BigInteger add( BigInteger[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigInteger b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.add( a[ i ] ); + return b; + } public static double add( double[] a ) { if ( a.length == 0 ) throw new IllegalArgumentException(); @@ -135,6 +153,14 @@ return b; } + public static BigDecimal subtract( BigDecimal a, BigDecimal b ) { + return a.subtract( b ); + } + + public static BigInteger subtract( BigInteger a, BigInteger b ) { + return a.subtract( b ); + } + public static double subtract( double a, double b ) { return a - b; } @@ -147,6 +173,26 @@ public static int subtract( int a, int b ) { return a - b; } + public static BigDecimal subtract( BigDecimal[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigDecimal b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.subtract( a[ i ] ); + return b; + } + public static BigInteger subtract( BigInteger[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigInteger b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.subtract( a[ i ] ); + return b; + } public static double subtract( double[] a ) { if ( a.length == 0 ) throw new IllegalArgumentException(); @@ -188,6 +234,14 @@ return b; } + public static BigDecimal multiply( BigDecimal a, BigDecimal b ) { + return a.multiply( b ); + } + + public static BigInteger multiply( BigInteger a, BigInteger b ) { + return a.multiply( b ); + } + public static double multiply( double a, double b ) { return a * b; } @@ -200,6 +254,26 @@ public static int multiply( int a, int b ) { return a * b; } + public static BigDecimal multiply( BigDecimal[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigDecimal b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.multiply( a[ i ] ); + return b; + } + public static BigInteger multiply( BigInteger[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigInteger b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.multiply( a[ i ] ); + return b; + } public static double multiply( double[] a ) { if ( a.length == 0 ) throw new IllegalArgumentException(); @@ -241,6 +315,19 @@ return b; } + public static BigDecimal divide( BigDecimal a, BigDecimal b ) { + try { + return a.divide( b, BigDecimal.ROUND_HALF_EVEN ); + } + catch ( Throwable e ) { + return a.divide( b, BigDecimal.ROUND_HALF_EVEN ); + } + } + + public static BigInteger divide( BigInteger a, BigInteger b ) { + return a.divide( b ); + } + public static double divide( double a, double b ) { return a / b; } @@ -253,6 +340,26 @@ public static int divide( int a, int b ) { return a / b; } + public static BigDecimal divide( BigDecimal[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigDecimal b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.divide( a[ i ], BigDecimal.ROUND_HALF_EVEN ); + return b; + } + public static BigInteger divide( BigInteger[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigInteger b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.divide( a[ i ] ); + return b; + } public static double divide( double[] a ) { if ( a.length == 0 ) throw new IllegalArgumentException(); @@ -294,6 +401,10 @@ return b; } + public static BigInteger mod( BigInteger a, BigInteger b ) { + return a.mod( b ); + } + public static double mod( double a, double b ) { return a % b; } @@ -306,6 +417,16 @@ public static int mod( int a, int b ) { return a % b; } + public static BigInteger mod( BigInteger[] a ) { + if ( a.length == 0 ) + throw new IllegalArgumentException(); + if ( a.length == 1 ) + return a[ 0 ]; + BigInteger b = a[ 0 ]; + for ( int i = 1; i < a.length; i++ ) + b = b.mod( a[ i ] ); + return b; + } public static double mod( double[] a ) { if ( a.length == 0 ) throw new IllegalArgumentException(); @@ -347,6 +468,139 @@ return b; } + // comparisons + public static boolean greaterThan(int x, int y) { + return x > y; + } + public static boolean greaterThan(long x, long y) { + return x > y; + } + public static boolean greaterThan(double x, double y) { + return x > y; + } + public static boolean greaterThan(BigInteger x, BigInteger y) { + return x.compareTo(y) > 0; + } + public static boolean greaterThan(BigDecimal x, BigDecimal y) { + return x.compareTo(y) > 0; + } + public static boolean lessThan(int x, int y) { + return x < y; + } + public static boolean lessThan(long x, long y) { + return x < y; + } + public static boolean lessThan(double x, double y) { + return x < y; + } + public static boolean lessThan(BigInteger x, BigInteger y) { + return x.compareTo(y) < 0; + } + public static boolean lessThan(BigDecimal x, BigDecimal y) { + return x.compareTo(y) < 0; + } + public static boolean equal(int x, int y) { + return x == y; + } + public static boolean equal(long x, long y) { + return x == y; + } + public static boolean equal(double x, double y) { + return x == y; + } + public static boolean equal(BigInteger x, BigInteger y) { + return x.compareTo(y) == 0; + } + public static boolean equal(BigDecimal x, BigDecimal y) { + return x.compareTo(y) == 0; + } + public static boolean notEqual(int x, int y) { + return x != y; + } + public static boolean notEqual(long x, long y) { + return x != y; + } + public static boolean notEqual(double x, double y) { + return x != y; + } + public static boolean notEqual(BigInteger x, BigInteger y) { + return x.compareTo(y) != 0; + } + public static boolean notEqual(BigDecimal x, BigDecimal y) { + return x.compareTo(y) != 0; + } + + public static BigInteger factorial( BigInteger x ) { + if ( x.compareTo( new BigInteger( "0" ) ) < 0 ) + throw new IllegalArgumentException( "number must be greater than 0" ); + BigInteger y = x; + for ( x = x.subtract( new BigInteger( "1" ) ); x.toString().compareTo( "1" ) > 0; x = x.subtract( new BigInteger( "1" ) ) ) { + y = y.multiply( x ); + } + return y; + } + + public static int factorial( double x ) { + return factorial( ( int ) x ); + } + + public static int factorial( float x ) { + return factorial( ( int ) x ); + } + + public static int factorial( int x ) { + if ( x < 0 ) + throw new IllegalArgumentException( "number must be greater than 0" ); + int y = x; + for ( x -= 1; x > 1; x-- ) + y *= x; + return y; + } + + public static BigDecimal min( BigDecimal a, BigDecimal b ) { + return a.min( b ); + } + + public static BigInteger min( BigInteger a, BigInteger b ) { + return a.min( b ); + } + + public static BigDecimal max( BigDecimal a, BigDecimal b ) { + return a.max( b ); + } + + public static BigInteger max( BigInteger a, BigInteger b ) { + return a.max( b ); + } + + /** + * y raised to the x power + */ + public static BigInteger pow( BigInteger y, BigInteger x ) { + int exp = x.intValue(); + if ( exp < 1 ) + throw new IllegalArgumentException( "Exponent must be greater than 0" ); + return y.pow( x.intValue() ); + } + + /** + * y raised to the x power + */ + public static BigDecimal pow( BigDecimal y, BigDecimal x ) { + if ( x.compareTo( new BigDecimal( "1" ) ) <= 0 ) { + throw new ArithmeticException( "Powers of BigDecimals must be integers greater than 1" ); + } + String exp = x.toString(); + if ( exp.indexOf( "." ) > 0 ) + exp = exp.substring( 0, exp.indexOf( "." ) ); + BigInteger e = new BigInteger( exp ); + BigDecimal z = new BigDecimal( y.toString() ); + for ( ;e.compareTo( BigInteger.ONE ) > 0; e = e.subtract( BigInteger.ONE ) ) { + y = y.multiply( z ); + } + return y; + } + /** * Do a mathematical calculation. The allowed operations are all * operations supported by java.lang.Math and this class. Assumes data @@ -364,22 +618,24 @@ * @param op the name of a mathematical operation to perform * @param type the data type of the operands * @param the operands for the operation + * @return the result of the calculation. For boolean operations, returns + * 1 for true, 0 for false; */ public Number calculate( String op, String type, String[] operands ) { try { - if ( operands.length > 2 ) { - if ( op.equals( "add" ) || + if ( operands.length >= 2 && ( op.equals( "add" ) || op.equals( "subtract" ) || op.equals( "multiply" ) || op.equals( "divide" ) || - op.equals( "mod" ) ) { + op.equals( "mod" ) ) ) { return calculateArray( op, type, operands ); } - else + + if ( operands.length > 2 ) throw new IllegalArgumentException( "too many operands" ); - } Class c; + Method m; if ( strict ) c = Class.forName( "java.lang.StrictMath" ); else @@ -388,7 +644,7 @@ // check if op is 'random'. Random is a special case in that it is // the only method in Math that takes no parameters. if ( op.equals( "random" ) ) { - Method m = c.getDeclaredMethod( op, new Class[] {} ); + m = c.getDeclaredMethod( op, new Class[] {} ); Object result = m.invoke( c, null ); return ( Number ) result; } @@ -399,20 +655,17 @@ for ( int i = 0; i < methods.length; i++ ) { String name = methods[ i ].getName(); if ( name.equals( op ) ) { - candidates.addElement( methods[ i ] ); + candidates.addElement( new Candidate( c, methods[ i ] ) ); } } - if ( candidates.size() == 0 ) { - // try the other Math - //c = Class.forName( "ise.antelope.tasks.Math" ); + // also look for candidate methods in this class c = this.getClass(); methods = c.getDeclaredMethods(); for ( int i = 0; i < methods.length; i++ ) { String name = methods[ i ].getName(); if ( name.equals( op ) ) { - candidates.addElement( methods[ i ] ); - } + candidates.addElement( new Candidate( c, methods[ i ] ) ); } } @@ -430,16 +683,17 @@ //int paramCount = ( ( Method ) candidates.elementAt( 0 ) ).getParameterTypes().length; int paramCount = -1; try { - for (int i = 0; i <= candidates.size(); i++) { - Method candidate = (Method)candidates.elementAt(i); - paramCount = candidate.getParameterTypes().length; - if (paramCount == operands.length) + for ( int i = 0; i <= candidates.size(); i++ ) { + Candidate candidate = ( Candidate ) candidates.elementAt( i ); + Method method = candidate.getCandidateMethod(); + paramCount = method.getParameterTypes().length; + if ( paramCount == operands.length ) break; } } - catch(Exception e) { - throw new RuntimeException("Wrong number of arguments, have " + - operands.length + ", but can't find corresponding method."); + catch ( Exception e ) { + throw new RuntimeException( "Wrong number of arguments, have " + + operands.length + ", but can't find corresponding method." ); } // make sure there are enough arguments to pass to the method @@ -453,14 +707,18 @@ // typeClass from the method itself, not the desired. Class typeClass = null; if ( candidates.size() == 1 ) { - Method m = ( Method ) candidates.elementAt( 0 ); + Candidate candidate = ( Candidate ) candidates.elementAt( 0 ); + c = candidate.getCandidateClass(); + m = candidate.getCandidateMethod(); typeClass = m.getParameterTypes() [ 0 ]; } else { // check each candidate to find one with the desired type Enumeration en = candidates.elements(); while ( en.hasMoreElements() ) { - Method m = ( Method ) en.nextElement(); + Candidate candidate = ( Candidate ) en.nextElement(); + c = candidate.getCandidateClass(); + m = candidate.getCandidateMethod(); if ( m.getParameterTypes() [ 0 ].equals( wantTypeClass ) ) { typeClass = wantTypeClass; break; @@ -475,17 +733,33 @@ for ( int i = 0; i < paramCount; i++ ) { paramTypes[ i ] = typeClass; } - Method m = c.getDeclaredMethod( op, paramTypes ); + m = c.getDeclaredMethod( op, paramTypes ); + //System.out.println( "Math.calculate, invoking: " + m.toString() ); // load the parameters and invoke the method Object[] params = getParams( typeClass, operands ); - Object result = m.invoke( c, params ); + try { + //System.out.println( "Math.calculateArray, invoking: " + m.toString() ); + Object result = m.invoke( c, params ); + if (result instanceof Boolean) { + result = new Integer(((Boolean)result).booleanValue() ? 1 : 0); + } return ( Number ) result; - + } + catch ( InvocationTargetException ite ) { + Throwable t = ite.getCause(); + if ( t != null && t instanceof ArithmeticException ) { + throw ( ArithmeticException ) t; + } + else { + throw ite; + } + } } catch ( Exception e ) { - e.printStackTrace(); + if ( e instanceof RuntimeException ) + throw ( RuntimeException ) e; } return null; } @@ -534,13 +808,31 @@ if ( m.getParameterTypes() [ 0 ].equals( wantTypeClass.getClass() ) ) { typeClass = getDataType( type ); Object[] params = getParamsArray( typeClass, operands ); + try { + //System.out.println( "Math.calculateArray, invoking: " + m.toString() ); Object result = m.invoke( c, params ); return ( Number ) result; } + catch ( InvocationTargetException ite ) { + Throwable t = ite.getCause(); + if ( t != null && t instanceof ArithmeticException ) { + //System.out.println( "caught ArithmeticException in Math" ); + throw ( ArithmeticException ) t; + } + else { + //System.out.println( "throwing " + ite.getMessage() ); + throw ite; + } + } + } } } catch ( Exception e ) { e.printStackTrace(); + if ( e instanceof ArithmeticException ) { + //System.out.println("rethrowing " + e.getMessage()); + throw ( ArithmeticException ) e; + } } return null; } @@ -564,10 +856,24 @@ else if ( type.equals( "float" ) ) { return Float.TYPE; } - else { - return Double.TYPE; + else if ( type.equals( "bigint" ) ) { + try { + return Class.forName( "java.math.BigInteger" ); + } + catch ( Exception e ) { + //e.printStackTrace(); } } + else if ( type.equals( "bigdecimal" ) ) { + try { + return Class.forName( "java.math.BigDecimal" ); + } + catch ( Exception e ) { + //e.printStackTrace(); + } + } + return Double.TYPE; + } /** * Converts a string representing a data type into an Array. @@ -587,6 +893,12 @@ else if ( type.equals( "float" ) ) { return Array.newInstance( Float.TYPE, length ); } + else if ( type.equals( "bigdecimal" ) ) { + return Array.newInstance( BIGDECIMAL_TYPE, length ); + } + else if ( type.equals( "bigint" ) ) { + return Array.newInstance( BIGINT_TYPE, length ); + } else { return Array.newInstance( Double.TYPE, length ); } @@ -598,7 +910,17 @@ private Object[] getParams( Class typeClass, String[] operands ) { int paramCount = operands.length; Object[] params = new Object[ paramCount ]; - if ( typeClass == Double.TYPE ) { + if ( typeClass == BIGDECIMAL_TYPE ) { + for ( int i = 0; i < paramCount; i++ ) { + params[ i ] = new BigDecimal( operands[ i ] ); + } + } + else if ( typeClass == BIGINT_TYPE ) { + for ( int i = 0; i < paramCount; i++ ) { + params[ i ] = new BigInteger( operands[ i ] ); + } + } + else if ( typeClass == Double.TYPE ) { for ( int i = 0; i < paramCount; i++ ) { params[ i ] = new Double( operands[ i ] ); } @@ -629,7 +951,21 @@ */ private Object[] getParamsArray( Class typeClass, String[] operands ) { int paramCount = operands.length; - if ( typeClass == Double.TYPE ) { + if ( typeClass == BIGDECIMAL_TYPE ) { + BigDecimal[] array = ( BigDecimal[] ) Array.newInstance( typeClass, operands.length ); + for ( int i = 0; i < paramCount; i++ ) { + array[ i ] = new BigDecimal( operands[ i ] ); + } + return new Object[] {array}; + } + else if ( typeClass == BIGINT_TYPE ) { + BigInteger[] array = ( BigInteger[] ) Array.newInstance( typeClass, operands.length ); + for ( int i = 0; i < paramCount; i++ ) { + array[ i ] = new BigInteger( operands[ i ] ); + } + return new Object[] {array}; + } + else if ( typeClass == Double.TYPE ) { double[] array = ( double[] ) Array.newInstance( typeClass, operands.length ); for ( int i = 0; i < paramCount; i++ ) { Array.setDouble( array, i, new Double( operands[ i ] ).doubleValue() ); @@ -654,14 +990,26 @@ // Integer.TYPE is only other choice Object array = Array.newInstance( typeClass, operands.length ); for ( int i = 0; i < paramCount; i++ ) { + if (operands[i].indexOf(".") > 0) + operands[i] = operands[i].substring(0, operands[i].indexOf(".")); Array.setInt( array, i, new Integer( operands[ i ] ).intValue() ); } return new Object[] {array}; } } - public static void main ( String[] args ) { - Math math = new Math(); - System.out.println( math.calculate( "add", new String[] {"6", "5", "4"} ) ); + public class Candidate { + private Class c; + private Method m; + public Candidate( Class c, Method m ) { + this.c = c; + this.m = m; + } + public Class getCandidateClass() { + return c; + } + public Method getCandidateMethod() { + return m; + } } } File [changed]: MathTask.java Url: http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/tasks/MathTask.java?r1=1.1&r2=1.2 Delta lines: +2 -2 ------------------- --- MathTask.java 15 Feb 2004 22:15:19 -0000 1.1 +++ MathTask.java 26 Sep 2004 03:40:34 -0000 1.2 @@ -173,12 +173,12 @@ if ( operand1 != null ) { Num num = new Num(); num.setValue( operand1 ); - op.addNum( num ); + op.addConfiguredNum( num ); } if ( operand2 != null ) { Num num = new Num(); num.setValue( operand2 ); - op.addNum( num ); + op.addConfiguredNum( num ); } } if ( op == null ) File [changed]: Num.java Url: http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/tasks/Num.java?r1=1.1&r2=1.2 Delta lines: +36 -71 --------------------- --- Num.java 15 Feb 2004 22:15:19 -0000 1.1 +++ Num.java 26 Sep 2004 03:40:34 -0000 1.2 @@ -1,62 +1,9 @@ -/* -* The Apache Software License, Version 1.1 -* -* Copyright (c) 2001-2002 The Apache Software Foundation. All rights -* reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* 3. The end-user documentation included with the redistribution, if -* any, must include the following acknowlegement: -* "This product includes software developed by the -* Apache Software Foundation (http://www.apache.org/)." -* Alternately, this acknowlegement may appear in the software itself, -* if and wherever such third-party acknowlegements normally appear. -* -* 4. The names "The Jakarta Project", "Ant", and "Apache Software -* Foundation" must not be used to endorse or promote products derived -* from this software without prior written permission. For written -* permission, please contact apache@apache.org. -* -* 5. Products derived from this software may not be called "Apache" -* nor may "Apache" appear in their names without prior written -* permission of the Apache Group. -* -* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR -* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -* ==================================================================== -* -* This software consists of voluntary contributions made by many -* individuals on behalf of the Apache Software Foundation. For more -* information on the Apache Software Foundation, please see -* . -*/ package ise.antelope.tasks; -import org.apache.tools.ant.BuildException; /** * Represents a number. + *

Copyright 2003, Dale Anson, all rights reserved * @author Dale Anson, danson@germane-software.com */ public class Num { @@ -66,6 +13,13 @@ private String datatype = null; + public Num() { + } + + public Num( String value ) { + setValue( value ); + } + /** * Set the value for this number. This string must parse to the set * datatype, for example, setting value to "7.992" and datatype to INT @@ -74,10 +28,10 @@ * @param value the value for this number */ public void setValue( String value ) { - if (value.equals("E")) - value = String.valueOf(java.lang.Math.E); - else if (value.equals("PI")) - value = String.valueOf(java.lang.Math.PI); + if ( value.equals( "E" ) ) + value = String.valueOf( java.lang.Math.E ); + else if ( value.equals( "PI" ) ) + value = String.valueOf( java.lang.Math.PI ); this.value = value; } @@ -86,17 +40,26 @@ * Integer, Long, Float, or Double. */ public Number getValue() { - if (datatype == null) + try { + if ( datatype == null ) datatype = "double"; - if ( datatype.equals("int") ) + if ( datatype.equals( "int" ) ) return new Integer( value ); - if ( datatype.equals("long" )) + if ( datatype.equals( "long" ) ) return new Long( value ); - if ( datatype.equals("float" )) + if ( datatype.equals( "float" ) ) return new Float( value ); - if ( datatype.equals("double" )) + if ( datatype.equals( "double" ) ) return new Double( value ); - throw new BuildException( "Invalid datatype." ); + if ( datatype.equals( "bigint" ) ) + return new java.math.BigInteger( value ); + if ( datatype.equals( "bigdecimal" ) ) + return new java.math.BigDecimal( value ); + throw new RuntimeException( "Invalid datatype." ); + } + catch ( NumberFormatException nfe ) { + return new Double( value ); + } } /** @@ -111,12 +74,14 @@ * @return the datatype as one of the defined types. */ public String getDatatype() { - if (datatype == null) + if ( datatype == null ) datatype = "double"; return datatype; } public String toString() { + if (value == null) + return null; return getValue().toString(); } } File [changed]: Op.java Url: http://antelope.tigris.org/source/browse/antelope/src/ise/antelope/tasks/Op.java?r1=1.2&r2=1.3 Delta lines: +44 -66 --------------------- --- Op.java 4 Sep 2004 03:52:16 -0000 1.2 +++ Op.java 26 Sep 2004 03:40:34 -0000 1.3 @@ -1,64 +1,11 @@ -/* -* The Apache Software License, Version 1.1 -* -* Copyright (c) 2001-2002 The Apache Software Foundation. All rights -* reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* 3. The end-user documentation included with the redistribution, if -* any, must include the following acknowlegement: -* "This product includes software developed by the -* Apache Software Foundation (http://www.apache.org/)." -* Alternately, this acknowlegement may appear in the software itself, -* if and wherever such third-party acknowlegements normally appear. -* -* 4. The names "The Jakarta Project", "Ant", and "Apache Software -* Foundation" must not be used to endorse or promote products derived -* from this software without prior written permission. For written -* permission, please contact apache@apache.org. -* -* 5. Products derived from this software may not be called "Apache" -* nor may "Apache" appear in their names without prior written -* permission of the Apache Group. -* -* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR -* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -* ==================================================================== -* -* This software consists of voluntary contributions made by many -* individuals on behalf of the Apache Software Foundation. For more -* information on the Apache Software Foundation, please see -* . -*/ package ise.antelope.tasks; -import org.apache.tools.ant.BuildException; import java.util.Vector; import java.util.Enumeration; /** * Represents a mathematical operation. + *

Copyright 2003, Dale Anson, all rights reserved * @author Dale Anson, danson@germane-software.com */ public class Op { @@ -77,6 +24,19 @@ // should the StrictMath library be used? private boolean _strict = false; + public Op() { + + } + + public Op(String op) { + setOp(op); + } + + public Op(String op, String type) { + setOp(op); + setDatatype(type); + } + /** * Set the operation. */ @@ -85,11 +45,11 @@ operation = "add"; else if (op.equals("-")) operation = "subtract"; - else if (op.equals("*")) + else if (op.equals("*") || op.equals("x")) operation = "multiply"; - else if (op.equals("/")) + else if (op.equals("/") || op.equals( "รท" ) ) operation = "divide"; - else if (op.equals("%")) + else if (op.equals("%") || op.equals("\\")) operation = "mod"; else operation = op; @@ -100,8 +60,10 @@ * numbers to support formulas like 5 + 4 + 3 + 2 + 1. * @param num a number to use in this operation */ - public void addNum( Num num ) { + public void addConfiguredNum( Num num ) { nums.addElement( num ); + System.out.println("Op.addNum " + num); + } /** @@ -112,11 +74,13 @@ if ( p.equals( "int" ) || p.equals( "long" ) || p.equals( "float" ) || - p.equals( "double" ) ) + p.equals( "double" ) || + p.equals( "bigint") || + p.equals( "bigdecimal")) datatype = p; else - throw new BuildException( "Invalid datatype: " + p + - ". Must be one of int, long, float, or double." ); + throw new IllegalArgumentException( "Invalid datatype: " + p + + ". Must be one of int, long, float, double, bigint, or bigdouble." ); } /** @@ -126,7 +90,9 @@ public void addConfiguredOp( Op op ) { if ( datatype != null ) op.setDatatype( datatype ); - ops.addElement( op ); + //ops.addElement( op ); + System.out.println("Op.addConfiguredOp"); + addConfiguredNum(op.calculate()); } /** @@ -142,9 +108,10 @@ */ public Num calculate() { if ( operation == null ) - throw new BuildException( "Operation not specified." ); + throw new RuntimeException( "Operation not specified." ); // calculate nested Ops + /* Enumeration en = ops.elements(); while ( en.hasMoreElements() ) { Op op = ( Op ) en.nextElement(); @@ -152,21 +119,32 @@ op.setDatatype( datatype ); nums.addElement( op.calculate() ); } + */ // make an array of operands + System.out.println("operation is " + operation + " on these numbers:"); String[] operands = new String[ nums.size() ]; - en = nums.elements(); + Enumeration en = nums.elements(); int i = 0; while ( en.hasMoreElements() ) { Num num = (Num)en.nextElement(); if (datatype != null) num.setDatatype(datatype); + System.out.println(num.toString()); operands[ i++ ] = num.toString(); } Math math = new Math(_strict); - Number number = math.calculate( operation, datatype, operands ); + Number number = null; + try { + number = math.calculate( operation, datatype, operands ); + } + catch(ArithmeticException e) { + throw e; + } + if (number == null) + throw new ArithmeticException("math error"); Num num = new Num(); num.setValue(number.toString()); num.setDatatype(datatype); Directory: /antelope/src/ise/library/ ===================================== File [changed]: PrivilegedAccessor.java Url: http://antelope.tigris.org/source/browse/antelope/src/ise/library/PrivilegedAccessor.java?r1=1.2&r2=1.3 Delta lines: +1 -1 ------------------- --- PrivilegedAccessor.java 8 May 2004 02:42:56 -0000 1.2 +++ PrivilegedAccessor.java 26 Sep 2004 03:40:34 -0000 1.3 @@ -91,7 +91,7 @@ for ( int i = 0; i < methods.length; i++ ) { Method method = methods[ i ]; Class[] paramTypes = method.getParameterTypes(); - if ( compare( paramTypes, args ) ) { + if ( method.getName( ).equals( methodName ) && compare( paramTypes, args ) ) { return method.invoke( instance, args ); } } --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@antelope.tigris.org For additional commands, e-mail: cvs-help@antelope.tigris.org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /antelope/, /antelope/src/ise/antelope/common/, /antelope/src/ise/antelope/plugin/, /antelope/src/ise/antelope/tasks/, /antelope/src/ise/library/ danson Dale Anson 2004-09-25 20:40:34 PDT
Messages per page: