← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20944: minor fixes, support multiple arguments to operator

 

------------------------------------------------------------
revno: 20944
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-11-04 13:46:21 +0700
message:
  minor fixes, support multiple arguments to operator
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Between.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Equal.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqual.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThan.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILike.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/In.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqual.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThan.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Like.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNull.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Null.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.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-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Between.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Between.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Between.java	2015-11-04 06:46:21 +0000
@@ -37,9 +37,9 @@
  */
 public class Between extends Operator
 {
-    public Between( String propertyValue )
+    public Between( String arg )
     {
-        super( propertyValue, Typed.from( String.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Number.class, Date.class ), arg );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Equal.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Equal.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Equal.java	2015-11-04 06:46:21 +0000
@@ -38,15 +38,15 @@
  */
 public class Equal extends Operator
 {
-    public Equal( String propertyValue )
+    public Equal( String arg )
     {
-        super( propertyValue, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }
@@ -95,7 +95,7 @@
         }
         else if ( Enum.class.isInstance( value ) )
         {
-            String s1 = propertyValue;
+            String s1 = args.get( 0 );
             String s2 = String.valueOf( value );
 
             return s2.equals( s1 );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqual.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqual.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqual.java	2015-11-04 06:46:21 +0000
@@ -38,15 +38,15 @@
  */
 public class GreaterEqual extends Operator
 {
-    public GreaterEqual( String propertyValue )
+    public GreaterEqual( String arg )
     {
-        super( propertyValue, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThan.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThan.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThan.java	2015-11-04 06:46:21 +0000
@@ -38,15 +38,15 @@
  */
 public class GreaterThan extends Operator
 {
-    public GreaterThan( String propertyValue )
+    public GreaterThan( String arg )
     {
-        super( propertyValue, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILike.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILike.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILike.java	2015-11-04 06:46:21 +0000
@@ -35,15 +35,15 @@
  */
 public class ILike extends Operator
 {
-    public ILike( String propertyValue )
+    public ILike( String arg )
     {
-        super( propertyValue, Typed.from( String.class ) );
+        super( Typed.from( String.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/In.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/In.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/In.java	2015-11-04 06:46:21 +0000
@@ -38,9 +38,9 @@
  */
 public class In extends Operator
 {
-    public In( String propertyValue )
+    public In( String arg )
     {
-        super( propertyValue, Typed.from( Collection.class ) );
+        super( Typed.from( Collection.class ), arg );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqual.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqual.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqual.java	2015-11-04 06:46:21 +0000
@@ -38,15 +38,15 @@
  */
 public class LessEqual extends Operator
 {
-    public LessEqual( String propertyValue )
+    public LessEqual( String arg )
     {
-        super( propertyValue, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThan.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThan.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThan.java	2015-11-04 06:46:21 +0000
@@ -38,15 +38,15 @@
  */
 public class LessThan extends Operator
 {
-    public LessThan( String propertyValue )
+    public LessThan( String arg )
     {
-        super( propertyValue, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Like.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Like.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Like.java	2015-11-04 06:46:21 +0000
@@ -35,15 +35,15 @@
  */
 public class Like extends Operator
 {
-    public Like( String propertyValue )
+    public Like( String arg )
     {
-        super( propertyValue, Typed.from( String.class ) );
+        super( Typed.from( String.class ), arg );
     }
 
     @Override
     public boolean test( Object value )
     {
-        if ( propertyValue == null || value == null )
+        if ( args.isEmpty() || value == null )
         {
             return false;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNull.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNull.java	2015-11-04 06:08:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNull.java	2015-11-04 06:46:21 +0000
@@ -39,7 +39,7 @@
 {
     public NotNull()
     {
-        super( null, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Null.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Null.java	2015-11-04 06:08:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Null.java	2015-11-04 06:46:21 +0000
@@ -39,7 +39,7 @@
 {
     public Null()
     {
-        super( null, Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
+        super( Typed.from( String.class, Boolean.class, Number.class, Date.class ) );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java	2015-11-04 05:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java	2015-11-04 06:46:21 +0000
@@ -31,24 +31,44 @@
 import org.hisp.dhis.query.QueryUtils;
 import org.hisp.dhis.query.Typed;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public abstract class Operator
 {
-    protected final String propertyValue;
+    protected final List<String> args = new ArrayList<>();
 
     protected final Typed typed;
 
-    public Operator( String propertyValue, Typed typed )
-    {
-        this.propertyValue = propertyValue;
-        this.typed = typed;
+    public Operator( Typed typed )
+    {
+        this.typed = typed;
+    }
+
+    public Operator( Typed typed, String arg )
+    {
+        this.typed = typed;
+        this.args.add( arg );
+    }
+
+    public Operator( Typed typed, String... args )
+    {
+        this.typed = typed;
+        Collections.addAll( this.args, args );
+    }
+
+    protected <T> T getValue( Class<T> klass, int idx )
+    {
+        return QueryUtils.getValue( klass, args.get( idx ) );
     }
 
     protected <T> T getValue( Class<T> klass )
     {
-        return QueryUtils.getValue( klass, propertyValue );
+        return getValue( klass, 0 );
     }
 
     protected <T> T getValue( Class<T> klass, Object value )