dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38549
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19640: Moved jep functions from commons to support-system. Removed jep dependency from commons.
------------------------------------------------------------
revno: 19640
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-07-14 11:47:47 +0200
message:
Moved jep functions from commons to support-system. Removed jep dependency from commons.
removed:
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/OneIfZeroOrPositiveFunction.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/UnaryDoubleFunction.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ZeroIfNegativeFunction.java
added:
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionFunctions.java
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-commons/pom.xml
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.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
=== modified file 'dhis-2/dhis-support/dhis-support-commons/pom.xml'
--- dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-07-10 16:10:28 +0000
+++ dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-07-14 09:47:47 +0000
@@ -35,10 +35,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl</artifactId>
</dependency>
- <dependency>
- <groupId>org.scijava</groupId>
- <artifactId>jep</artifactId>
- </dependency>
</dependencies>
<properties>
=== removed directory 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math'
=== removed file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java 2015-07-10 11:43:34 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
-package org.hisp.dhis.commons.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.
- */
-
-public class ExpressionFunctions
-{
- public static final String NAMESPACE = "d2";
-
- /**
- * Function which will return zero if the argument is a negative number.
- *
- * @param value the value, must be a number.
- * @return a Double.
- */
- public static Double zing( Number value )
- {
- if ( value == null )
- {
- throw new IllegalArgumentException( "Argument is null: " + value );
- }
-
- return Math.max( 0d, value.doubleValue() );
- }
-
- /**
- * Function which will return one if the argument is zero or a positive
- * number, and zero if not.
- *
- * @param value the value, must be a number.
- * @return a Double.
- */
- public static Double oizp( Number value )
- {
- if ( value == null )
- {
- throw new IllegalArgumentException( "Argument is null: " + value );
- }
-
- return ( value.doubleValue() >= 0d ) ? 1d : 0d;
- }
-}
=== removed file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/OneIfZeroOrPositiveFunction.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/OneIfZeroOrPositiveFunction.java 2015-07-10 11:32:13 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/OneIfZeroOrPositiveFunction.java 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-package org.hisp.dhis.commons.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-commons/src/main/java/org/hisp/dhis/commons/math/UnaryDoubleFunction.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/UnaryDoubleFunction.java 2015-05-28 18:23:26 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/UnaryDoubleFunction.java 1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-package org.hisp.dhis.commons.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
-{
- public 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-commons/src/main/java/org/hisp/dhis/commons/math/ZeroIfNegativeFunction.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ZeroIfNegativeFunction.java 2015-05-28 18:23:26 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ZeroIfNegativeFunction.java 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-package org.hisp.dhis.commons.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-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java 2015-06-18 07:03:42 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java 2015-07-14 09:47:47 +0000
@@ -127,10 +127,12 @@
*
* @param username the username to use for authentication.
* @param password the password to use for authentication.
- * @return the
+ * @return the encoded string.
*/
public static String getBasicAuthString( String username, String password )
- {
+ {
+ //TODO replace with Java 8 Base64
+
String string = username + ":" + password;
return "Basic " + Base64.encodeBase64String( string.getBytes() );
=== added file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionFunctions.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionFunctions.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionFunctions.java 2015-07-14 09:47:47 +0000
@@ -0,0 +1,67 @@
+package org.hisp.dhis.commons.util;
+
+/*
+ * 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.
+ */
+
+public class ExpressionFunctions
+{
+ public static final String NAMESPACE = "d2";
+
+ /**
+ * Function which will return zero if the argument is a negative number.
+ *
+ * @param value the value, must be a number.
+ * @return a Double.
+ */
+ public static Double zing( Number value )
+ {
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "Argument is null: " + value );
+ }
+
+ return Math.max( 0d, value.doubleValue() );
+ }
+
+ /**
+ * Function which will return one if the argument is zero or a positive
+ * number, and zero if not.
+ *
+ * @param value the value, must be a number.
+ * @return a Double.
+ */
+ public static Double oizp( Number value )
+ {
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "Argument is null: " + value );
+ }
+
+ return ( value.doubleValue() >= 0d ) ? 1d : 0d;
+ }
+}
=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java 2015-07-10 17:25:59 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java 2015-07-14 09:47:47 +0000
@@ -33,7 +33,6 @@
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.JexlException;
import org.apache.commons.jexl2.MapContext;
-import org.hisp.dhis.commons.math.ExpressionFunctions;
import java.util.HashMap;
import java.util.Map;
=== added directory 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math'
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/OneIfZeroOrPositiveFunction.java 2015-07-14 09:47:47 +0000
@@ -0,0 +1,52 @@
+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;
+ }
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/UnaryDoubleFunction.java 2015-07-14 09:47:47 +0000
@@ -0,0 +1,72 @@
+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
+{
+ public 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 );
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/math/ZeroIfNegativeFunction.java 2015-07-14 09:47:47 +0000
@@ -0,0 +1,52 @@
+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-07-10 11:32:13 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2015-07-14 09:47:47 +0000
@@ -38,8 +38,8 @@
import org.apache.commons.validator.routines.DoubleValidator;
import org.apache.commons.validator.routines.IntegerValidator;
import org.hisp.dhis.expression.Operator;
-import org.hisp.dhis.commons.math.OneIfZeroOrPositiveFunction;
-import org.hisp.dhis.commons.math.ZeroIfNegativeFunction;
+import org.hisp.dhis.system.math.OneIfZeroOrPositiveFunction;
+import org.hisp.dhis.system.math.ZeroIfNegativeFunction;
import org.nfunk.jep.JEP;
/**