dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42244
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21586: Minor, introduce enum for order Direction
------------------------------------------------------------
revno: 21586
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-01-05 17:16:27 +0700
message:
Minor, introduce enum for order Direction
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Direction.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.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
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Direction.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Direction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Direction.java 2016-01-05 10:16:27 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.query;
+
+/*
+ * Copyright (c) 2004-2016, 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.
+ */
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public enum Direction
+{
+ ASCENDING, DESCENDING
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java 2016-01-05 09:05:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java 2016-01-05 10:16:27 +0000
@@ -40,16 +40,16 @@
*/
public class Order
{
- private boolean ascending;
+ private Direction direction;
private boolean ignoreCase;
private Property property;
- public Order( Property property, boolean ascending )
+ public Order( Property property, Direction direction )
{
this.property = property;
- this.ascending = ascending;
+ this.direction = direction;
}
public Order ignoreCase()
@@ -60,7 +60,7 @@
public boolean isAscending()
{
- return ascending;
+ return Direction.ASCENDING == direction;
}
public boolean isIgnoreCase()
@@ -98,31 +98,31 @@
String value1 = ignoreCase ? ((String) o1).toLowerCase() : (String) o1;
String value2 = ignoreCase ? ((String) o2).toLowerCase() : (String) o2;
- return ascending ? value1.compareTo( value2 ) : value2.compareTo( value1 );
+ return isAscending() ? value1.compareTo( value2 ) : value2.compareTo( value1 );
}
if ( Boolean.class.isInstance( o1 ) && Boolean.class.isInstance( o2 ) )
{
- return ascending ? ((Boolean) o1).compareTo( (Boolean) o2 ) : ((Boolean) o2).compareTo( (Boolean) o1 );
+ return isAscending() ? ((Boolean) o1).compareTo( (Boolean) o2 ) : ((Boolean) o2).compareTo( (Boolean) o1 );
}
else if ( Integer.class.isInstance( o1 ) && Integer.class.isInstance( o2 ) )
{
- return ascending ? ((Integer) o1).compareTo( (Integer) o2 ) : ((Integer) o2).compareTo( (Integer) o1 );
+ return isAscending() ? ((Integer) o1).compareTo( (Integer) o2 ) : ((Integer) o2).compareTo( (Integer) o1 );
}
else if ( Float.class.isInstance( o1 ) && Float.class.isInstance( o2 ) )
{
- return ascending ? ((Float) o1).compareTo( (Float) o2 ) : ((Float) o2).compareTo( (Float) o1 );
+ return isAscending() ? ((Float) o1).compareTo( (Float) o2 ) : ((Float) o2).compareTo( (Float) o1 );
}
else if ( Double.class.isInstance( o1 ) && Double.class.isInstance( o2 ) )
{
- return ascending ? ((Double) o1).compareTo( (Double) o2 ) : ((Double) o2).compareTo( (Double) o1 );
+ return isAscending() ? ((Double) o1).compareTo( (Double) o2 ) : ((Double) o2).compareTo( (Double) o1 );
}
else if ( Date.class.isInstance( o1 ) && Date.class.isInstance( o2 ) )
{
- return ascending ? ((Date) o1).compareTo( (Date) o2 ) : ((Date) o2).compareTo( (Date) o1 );
+ return isAscending() ? ((Date) o1).compareTo( (Date) o2 ) : ((Date) o2).compareTo( (Date) o1 );
}
else if ( Enum.class.isInstance( o1 ) && Enum.class.isInstance( o2 ) )
{
- return ascending ? String.valueOf( o1 ).compareTo( String.valueOf( o2 ) ) : String.valueOf( o2 ).compareTo( String.valueOf( o1 ) );
+ return isAscending() ? String.valueOf( o1 ).compareTo( String.valueOf( o2 ) ) : String.valueOf( o2 ).compareTo( String.valueOf( o1 ) );
}
return 0;
@@ -130,22 +130,22 @@
public static Order asc( Property property )
{
- return new Order( property, true );
+ return new Order( property, Direction.ASCENDING );
}
public static Order iasc( Property property )
{
- return new Order( property, true ).ignoreCase();
+ return new Order( property, Direction.ASCENDING ).ignoreCase();
}
public static Order desc( Property property )
{
- return new Order( property, false );
+ return new Order( property, Direction.DESCENDING );
}
public static Order idesc( Property property )
{
- return new Order( property, false ).ignoreCase();
+ return new Order( property, Direction.DESCENDING ).ignoreCase();
}
public static Order from( String direction, Property property )
@@ -168,7 +168,7 @@
@Override
public int hashCode()
{
- return Objects.hash( ascending, ignoreCase, property );
+ return Objects.hash( direction, ignoreCase, property );
}
@Override
@@ -186,18 +186,19 @@
final Order other = (Order) obj;
- return Objects.equals( this.ascending, other.ascending )
+ return Objects.equals( this.direction, other.direction )
&& Objects.equals( this.ignoreCase, other.ignoreCase )
&& Objects.equals( this.property, other.property );
}
+
@Override
public String toString()
{
return MoreObjects.toStringHelper( this )
- .add( "ascending", ascending )
+ .add( "direction", direction )
.add( "ignoreCase", ignoreCase )
- .add( "property", property != null ? property.getName() : null )
+ .add( "property", property )
.toString();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java 2016-01-05 10:16:27 +0000
@@ -294,7 +294,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "name" ), false ) );
+ query.addOrder( new Order( schema.getProperty( "name" ), Direction.DESCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
@@ -313,7 +313,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "name" ), true ) );
+ query.addOrder( new Order( schema.getProperty( "name" ), Direction.ASCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
@@ -332,7 +332,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "created" ), false ) );
+ query.addOrder( new Order( schema.getProperty( "created" ), Direction.DESCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
@@ -351,7 +351,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "created" ), true ) );
+ query.addOrder( new Order( schema.getProperty( "created" ), Direction.ASCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2016-01-05 10:16:27 +0000
@@ -437,7 +437,7 @@
Query query = Query.from( schema );
query.setObjects( dataElements );
- query.addOrder( new Order( schema.getProperty( "name" ), false ) );
+ query.addOrder( new Order( schema.getProperty( "name" ), Direction.DESCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
@@ -457,7 +457,7 @@
Query query = Query.from( schema );
query.setObjects( dataElements );
- query.addOrder( new Order( schema.getProperty( "name" ), true ) );
+ query.addOrder( new Order( schema.getProperty( "name" ), Direction.ASCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
@@ -477,7 +477,7 @@
Query query = Query.from( schema );
query.setObjects( dataElements );
- query.addOrder( new Order( schema.getProperty( "created" ), false ) );
+ query.addOrder( new Order( schema.getProperty( "created" ), Direction.DESCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
@@ -497,7 +497,7 @@
Query query = Query.from( schema );
query.setObjects( dataElements );
- query.addOrder( new Order( schema.getProperty( "created" ), true ) );
+ query.addOrder( new Order( schema.getProperty( "created" ), Direction.ASCENDING ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
assertEquals( 6, objects.size() );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java 2016-01-05 10:16:27 +0000
@@ -370,7 +370,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "name" ), false ) );
+ query.addOrder( new Order( schema.getProperty( "name" ), Direction.DESCENDING ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
assertEquals( 6, objects.size() );
@@ -389,7 +389,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "name" ), true ) );
+ query.addOrder( new Order( schema.getProperty( "name" ), Direction.ASCENDING ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
assertEquals( 6, objects.size() );
@@ -408,7 +408,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "created" ), false ) );
+ query.addOrder( new Order( schema.getProperty( "created" ), Direction.DESCENDING ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
assertEquals( 6, objects.size() );
@@ -427,7 +427,7 @@
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
- query.addOrder( new Order( schema.getProperty( "created" ), true ) );
+ query.addOrder( new Order( schema.getProperty( "created" ), Direction.ASCENDING ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
assertEquals( 6, objects.size() );