dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10695
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2934: Fixed bug with grid
------------------------------------------------------------
revno: 2934
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-02-28 20:51:49 +0100
message:
Fixed bug with grid
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.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-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2011-02-24 14:45:57 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2011-02-28 19:51:49 +0000
@@ -503,15 +503,19 @@
@SuppressWarnings("unchecked")
public int compare( List<Object> list1, List<Object> list2 )
{
- if ( order == 0 || list1 == null || list2 == null )
- {
- return 0;
- }
-
- if ( list1.get( columnIndex ) == null || !( list1.get( columnIndex ) instanceof Comparable<?> ) ||
- list2.get( columnIndex ) == null || !( list2.get( columnIndex ) instanceof Comparable<?> ) )
- {
- return 0;
+ if ( order == 0 )
+ {
+ return 0;
+ }
+
+ if ( list1 == null || list1.get( columnIndex ) == null || !( list1.get( columnIndex ) instanceof Comparable<?> ) )
+ {
+ return 1; // Null comes last
+ }
+
+ if ( list2 == null || list2.get( columnIndex ) == null || !( list2.get( columnIndex ) instanceof Comparable<?> ) )
+ {
+ return -1; // Null comes last
}
final Comparable<Object> value1 = (Comparable<Object>) list1.get( columnIndex );
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java 2011-02-23 23:26:47 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java 2011-02-28 19:51:49 +0000
@@ -333,6 +333,48 @@
}
@Test
+ public void testSortE()
+ {
+ Grid grid = new ListGrid();
+
+ grid.addRow().addValue( "two" ).addValue( 2 );
+ grid.addRow().addValue( "null" ).addValue( null );
+ grid.addRow().addValue( "three" ).addValue( 3 );
+
+ grid.sortGrid( 2, 1 );
+
+ List<Object> row1 = grid.getRow( 0 );
+ assertTrue( row1.contains( "three" ) );
+
+ List<Object> row2 = grid.getRow( 1 );
+ assertTrue( row2.contains( "two" ) );
+
+ List<Object> row3 = grid.getRow( 2 );
+ assertTrue( row3.contains( "null" ) );
+ }
+
+ @Test
+ public void testSortF()
+ {
+ Grid grid = new ListGrid();
+
+ grid.addRow().addValue( "two" ).addValue( 2 );
+ grid.addRow().addValue( "null" ).addValue( null );
+ grid.addRow().addValue( "one" ).addValue( 1 );
+
+ grid.sortGrid( 2, -1 );
+
+ List<Object> row1 = grid.getRow( 0 );
+ assertTrue( row1.contains( "one" ) );
+
+ List<Object> row2 = grid.getRow( 1 );
+ assertTrue( row2.contains( "two" ) );
+
+ List<Object> row3 = grid.getRow( 2 );
+ assertTrue( row3.contains( "null" ) );
+ }
+
+ @Test
public void testGridRowComparator()
{
List<List<Object>> lists = new ArrayList<List<Object>>();