← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20700: Removed unused JEP functions

 

------------------------------------------------------------
revno: 20700
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-10-14 15:33:26 +0200
message:
  Removed unused JEP functions
removed:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/OneIfZeroOrPositiveFunction.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/UnaryDoubleFunction.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/ZeroIfNegativeFunction.java
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== removed directory 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math'
=== removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/OneIfZeroOrPositiveFunction.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/OneIfZeroOrPositiveFunction.java	2015-07-14 09:47:47 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/OneIfZeroOrPositiveFunction.java	1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-package org.hisp.dhis.system.math;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 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.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
- */
-
-/**
- * JEP function which returns 1 if the argument is a zero or positive number, 0
- * otherwise.
- * 
- * @author Lars Helge Overland
- */
-public class OneIfZeroOrPositiveFunction
-    extends UnaryDoubleFunction
-{
-    public static final String NAME = "oizp";
-
-    public OneIfZeroOrPositiveFunction()
-    {
-        super();
-    }
-
-    @Override
-    public Double eval( double arg )
-    {
-        return ( arg >= 0d ) ? 1d : 0d;
-    }
-}

=== removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/UnaryDoubleFunction.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/UnaryDoubleFunction.java	2015-09-14 18:06:48 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/UnaryDoubleFunction.java	1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-package org.hisp.dhis.system.math;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 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.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
- */
-
-import org.nfunk.jep.ParseException;
-import org.nfunk.jep.function.PostfixMathCommand;
-
-import java.util.Stack;
-
-/**
- * Abstract JEP function for a single, numerical argument.
- * 
- * @author Lars Helge Overland
- */
-public abstract class UnaryDoubleFunction
-    extends PostfixMathCommand
-{
-    protected UnaryDoubleFunction()
-    {
-        super();
-
-        numberOfParameters = 1;
-    }
-    
-    @Override
-    @SuppressWarnings( { "rawtypes", "unchecked" } )
-    public void run( Stack inStack ) throws ParseException 
-    {
-        checkStack( inStack );
-        
-        Object param = inStack.pop();
-        
-        if ( param == null || !( param instanceof Double ) )
-        {
-            throw new ParseException( "Invalid parameter type, must be double: " + param );
-        }
-        
-        double arg = ( (Double) param ).doubleValue();
-        
-        Double result = eval( arg );
-        
-        inStack.push( result );
-    }
-    
-    public abstract Double eval( double arg );
-}

=== removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/ZeroIfNegativeFunction.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/ZeroIfNegativeFunction.java	2015-07-14 09:47:47 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/ZeroIfNegativeFunction.java	1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-package org.hisp.dhis.system.math;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 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.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
- */
-
-/**
- * JEP function which returns the value if the argument is a zero or positive 
- * number, 0 otherwise.
- * 
- * @author Lars Helge Overland
- */
-public class ZeroIfNegativeFunction
-    extends UnaryDoubleFunction
-{
-    public static final String NAME = "zing";
-    
-    public ZeroIfNegativeFunction()
-    {
-        super();
-    }
-
-    @Override
-    public Double eval( double arg )
-    {
-        return Math.max( 0d, arg );
-    }
-}

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2015-09-28 07:12:35 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2015-10-14 13:33:26 +0000
@@ -38,8 +38,6 @@
 import org.apache.commons.validator.routines.DoubleValidator;
 import org.apache.commons.validator.routines.IntegerValidator;
 import org.hisp.dhis.expression.Operator;
-import org.hisp.dhis.system.math.OneIfZeroOrPositiveFunction;
-import org.hisp.dhis.system.math.ZeroIfNegativeFunction;
 import org.nfunk.jep.JEP;
 
 /**
@@ -158,9 +156,6 @@
     {
         final JEP parser = new JEP();
         parser.addStandardFunctions();
-        parser.addStandardConstants();
-        parser.addFunction( OneIfZeroOrPositiveFunction.NAME, new OneIfZeroOrPositiveFunction() );
-        parser.addFunction( ZeroIfNegativeFunction.NAME, new ZeroIfNegativeFunction() );
         return parser;
     }
     

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2015-09-24 14:38:17 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2015-10-14 13:33:26 +0000
@@ -360,26 +360,4 @@
         assertEquals( 84d, MathUtils.calculateExpression( "70/1000*12*100" ), DELTA );
         assertEquals( 1158d, MathUtils.calculateExpression( "70+1000-12+100" ), DELTA );        
     }
-    
-    @Test
-    public void testCalculateExpressionOneIfZeroOrPositive()
-    {
-        assertEquals( 1d, MathUtils.calculateExpression( "oizp(314)" ), DELTA );
-        assertEquals( 1d, MathUtils.calculateExpression( "oizp(0)" ), DELTA );
-        assertEquals( 0d, MathUtils.calculateExpression( "oizp(-3)" ), DELTA );
-        assertEquals( 5d, MathUtils.calculateExpression( "4 + oizp(314)" ), DELTA );
-        assertEquals( 4d, MathUtils.calculateExpression( "oizp(0) + 3" ), DELTA );
-        assertEquals( 5d, MathUtils.calculateExpression( "oizp(-3) + 5" ), DELTA );
-    }
-
-    @Test
-    public void testCalculateExpressionZeroIfNegative()
-    {
-        assertEquals( 314d, MathUtils.calculateExpression( "zing(314)" ), DELTA );
-        assertEquals( 0d, MathUtils.calculateExpression( "zing(0)" ), DELTA );
-        assertEquals( 0d, MathUtils.calculateExpression( "zing(-3)" ), DELTA );
-        assertEquals( -3d, MathUtils.calculateExpression( "zing(0) - 3" ), DELTA );
-        assertEquals( 5d, MathUtils.calculateExpression( "zing(-3) + 5" ), DELTA );
-        assertEquals( -2d, MathUtils.calculateExpression( "zing(-3) - 2" ), DELTA );
-    }
 }