dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08083
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2407: Codestyle fix in Paging.java. Added generics to PagingSupportAction
------------------------------------------------------------
revno: 2407
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2010-10-21 18:27:08 +0200
message:
Codestyle fix in Paging.java. Added generics to PagingSupportAction
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.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/paging/Paging.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java 2010-07-06 16:01:15 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java 2010-10-21 16:27:08 +0000
@@ -1,3 +1,5 @@
+package org.hisp.dhis.system.paging;
+
/*
* Copyright (c) 2004-2009, University of Oslo
* All rights reserved.
@@ -24,8 +26,10 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package org.hisp.dhis.system.paging;
+/**
+ * @author Quang Nguyen
+ */
public class Paging
{
static final int MAX_ALLOWED_PAGE_SIZE = 50;
@@ -52,31 +56,30 @@
public String getBaseLink()
{
- if ( link.indexOf( "?" ) < 0 )
- return (new StringBuilder( String.valueOf( link ) )).append( "?" ).toString();
- else
- return (new StringBuilder( String.valueOf( link ) )).append( "&" ).toString();
+ return link.indexOf( "?" ) < 0 ? ( link + "?" ) : ( link + "&" );
}
public int getNumberOfPages()
{
- if ( total % pageSize == 0 )
- return total / pageSize;
- else
- return total / pageSize + 1;
+ return total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
}
public int getStartPage()
{
int startPage = 1;
+
if ( currentPage > 2 )
{
startPage = currentPage - 2;
+
if ( getNumberOfPages() - startPage < 4 )
{
startPage = getNumberOfPages() - 4;
+
if ( startPage <= 0 )
+ {
startPage = 1;
+ }
}
}
return startPage;
@@ -97,16 +100,16 @@
public int getCurrentPage()
{
if ( currentPage > total )
+ {
currentPage = total;
+ }
+
return currentPage;
}
public void setCurrentPage( int currentPage )
{
- if ( currentPage > 0 )
- this.currentPage = currentPage;
- else
- this.currentPage = 1;
+ this.currentPage = currentPage > 0 ? currentPage : 1;
}
public int getPageSize()
@@ -116,10 +119,7 @@
public void setPageSize( int pageSize )
{
- if ( pageSize > 0 )
- this.pageSize = pageSize;
- else
- this.pageSize = 50;
+ this.pageSize = pageSize > 0 ? pageSize : 50;
}
public int getTotal()
@@ -141,5 +141,4 @@
{
this.link = link;
}
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2010-10-05 11:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2010-10-21 16:27:08 +0000
@@ -1,5 +1,32 @@
package org.hisp.dhis.paging;
+/*
+ * Copyright (c) 2004-2009, 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 java.util.List;
import org.apache.struts2.ServletActionContext;
@@ -7,12 +34,10 @@
import com.opensymphony.xwork2.ActionSupport;
-
/**
* @author Quang Nguyen
- * @version Jul 11, 2010 10:01:40 PM
*/
-public abstract class ActionPagingSupport extends ActionSupport
+public abstract class ActionPagingSupport<T> extends ActionSupport
{
protected static final Integer DEFAULT_PAGE_SIZE = 50;
@@ -53,9 +78,9 @@
return resultPaging;
}
- protected List getBlockElement( List elementList, int startPos, int pageSize )
+ protected List<T> getBlockElement( List<T> elementList, int startPos, int pageSize )
{
- List returnList;
+ List<T> returnList;
try
{
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java 2010-09-23 16:02:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java 2010-10-21 16:27:08 +0000
@@ -51,7 +51,7 @@
* ch_bharath1 $
*/
public class GetDataElementListAction
- extends ActionPagingSupport
+ extends ActionPagingSupport<DataElement>
{
// -------------------------------------------------------------------------
// Dependencies
@@ -301,16 +301,17 @@
Collections.sort( dataDictionaries, new DataDictionaryNameComparator() );
}
-
+
private List<DataElement> searchByDataElementName( List<DataElement> dataElementList, String key )
- {
+ {
List<DataElement> result = new ArrayList<DataElement>();
- for(DataElement eachElement : dataElementList) {
- if(eachElement.getName().contains( key.trim() ) ) {
+ for ( DataElement eachElement : dataElementList )
+ {
+ if ( eachElement.getName().contains( key.trim() ) )
+ {
result.add( eachElement );
}
}
return result;
- }
-
+ }
}