dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12926
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4046: Improved PaginatedList
------------------------------------------------------------
revno: 4046
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-06-30 16:58:12 +0200
message:
Improved PaginatedList
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PaginatedList.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantAction.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/util/PaginatedList.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PaginatedList.java 2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PaginatedList.java 2011-06-30 14:58:12 +0000
@@ -42,14 +42,37 @@
*/
private static final long serialVersionUID = 6296545460322554660L;
- private final int pageSize;
+ public static final int DEFAULT_PAGE_SIZE = 10;
+
+ private int pageSize;
private int fromIndex = 0;
- public PaginatedList( Collection<? extends T> collection, int pageSize )
+ public PaginatedList( Collection<? extends T> collection )
{
super( collection );
+ this.pageSize = DEFAULT_PAGE_SIZE;
+ }
+
+ /**
+ * Sets page size.
+ */
+ public PaginatedList<T> setPageSize( int pageSize )
+ {
this.pageSize = pageSize;
+
+ return this;
+ }
+
+ /**
+ * Sets the number of pages. The page size will be calculated and set in
+ * order to provide the appropriate total number of pages.
+ */
+ public PaginatedList<T> setNumberOfPages( int pages )
+ {
+ this.pageSize = (int) Math.ceil( (double) size() / pages );
+
+ return this;
}
/**
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java 2011-01-20 22:08:42 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java 2011-06-30 14:58:12 +0000
@@ -43,7 +43,7 @@
@Test
public void testNextPage()
{
- PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C" ), 2 );
+ PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 );
List<String> page = list.nextPage();
@@ -66,7 +66,7 @@
@Test
public void testGetPageEmpty()
{
- PaginatedList<String> list = new PaginatedList<String>( new ArrayList<String>(), 2 );
+ PaginatedList<String> list = new PaginatedList<String>( new ArrayList<String>() ).setPageSize( 2 );
List<String> page = list.nextPage();
@@ -76,15 +76,15 @@
@Test
public void testPageCount()
{
- PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C" ), 2 );
+ PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 );
assertEquals( 2, list.pageCount() );
- list = new PaginatedList<String>( Arrays.asList( "A", "B", "C", "D" ), 2 );
+ list = new PaginatedList<String>( Arrays.asList( "A", "B", "C", "D" ) ).setPageSize( 2 );
assertEquals( 2, list.pageCount() );
- list = new PaginatedList<String>( Arrays.asList( "A", "B", "C", "D", "E" ), 2 );
+ list = new PaginatedList<String>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setPageSize( 2 );
assertEquals( 3, list.pageCount() );
}
@@ -92,7 +92,7 @@
@Test
public void testReset()
{
- PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C" ), 2 );
+ PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 );
assertTrue( list.nextPage().contains( "A" ) );
@@ -100,4 +100,40 @@
assertTrue( list.nextPage().contains( "A" ) );
}
+
+ @Test
+ public void testSetNumberOfPages()
+ {
+ PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setNumberOfPages( 3 );
+
+ assertEquals( 3, list.pageCount() );
+
+ assertEquals( 2, list.nextPage().size() );
+ }
+
+ @Test
+ public void testNextPageNumberOfPages()
+ {
+ PaginatedList<String> list = new PaginatedList<String>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setNumberOfPages( 2 );
+
+ List<String> page = list.nextPage();
+
+ assertNotNull( page );
+ assertEquals( 3, page.size() );
+ assertTrue( page.contains( "A" ) );
+ assertTrue( page.contains( "B" ) );
+ assertTrue( page.contains( "C" ) );
+
+ page = list.nextPage();
+
+ assertNotNull( page );
+ assertEquals( 2, page.size() );
+ assertTrue( page.contains( "D" ) );
+ assertTrue( page.contains( "E" ) );
+
+ page = list.nextPage();
+
+ assertNull( page );
+ }
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantAction.java 2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantAction.java 2011-06-30 14:58:12 +0000
@@ -79,7 +79,7 @@
public String execute()
{
constant = constantService.getConstant( id );
-System.out.println("\n\n constant : " + constant.getValue() );
+
return SUCCESS;
}
}