dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02483
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 825: Reduced object creation and number of if-statements in SortOrderManager.
------------------------------------------------------------
revno: 825
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-10-06 13:29:00 +0200
message:
Reduced object creation and number of if-statements in SortOrderManager.
modified:
dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java
dhis-2/dhis-options/src/main/resources/META-INF/dhis/beans.xml
--
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-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java'
--- dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java 2009-10-06 11:29:00 +0000
@@ -29,7 +29,9 @@
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.comparator.DataElementAlternativeNameComparator;
@@ -64,10 +66,46 @@
{
private final static String SETTING_NAME_SORT_ORDER = "currentSortOrder";
+ private Map<String, Comparator<DataElement>> dataElementComparators;
+ private Map<String, Comparator<Indicator>> indicatorComparators;
+ private Map<String, Comparator<OrganisationUnit>> organisationUnitComparators;
+ private Map<String, Comparator<DataSet>> dataSetComparators;
+
+ public void init()
+ {
+ dataElementComparators = new HashMap<String, Comparator<DataElement>>();
+ dataElementComparators.put( SORT_ORDER_NAME, new DataElementNameComparator() );
+ dataElementComparators.put( SORT_ORDER_SHORTNAME, new DataElementShortNameComparator() );
+ dataElementComparators.put( SORT_ORDER_ALTERNATIVENAME, new DataElementAlternativeNameComparator() );
+ dataElementComparators.put( SORT_ORDER_CODE, new DataElementCodeComparator() );
+ dataElementComparators.put( SORT_ORDER_CUSTOM, new DataElementSortOrderComparator() );
+
+ indicatorComparators = new HashMap<String, Comparator<Indicator>>();
+ indicatorComparators.put( SORT_ORDER_NAME, new IndicatorNameComparator() );
+ indicatorComparators.put( SORT_ORDER_SHORTNAME, new IndicatorShortNameComparator() );
+ indicatorComparators.put( SORT_ORDER_ALTERNATIVENAME, new IndicatorAlternativeNameComparator() );
+ indicatorComparators.put( SORT_ORDER_CODE, new IndicatorCodeComparator() );
+ indicatorComparators.put( SORT_ORDER_CUSTOM, new IndicatorSortOrderComparator() );
+
+ organisationUnitComparators = new HashMap<String, Comparator<OrganisationUnit>>();
+ organisationUnitComparators.put( SORT_ORDER_NAME, new OrganisationUnitNameComparator() );
+ organisationUnitComparators.put( SORT_ORDER_SHORTNAME, new OrganisationUnitShortNameComparator() );
+ organisationUnitComparators.put( SORT_ORDER_ALTERNATIVENAME, new OrganisationUnitNameComparator() ); // SIC
+ organisationUnitComparators.put( SORT_ORDER_CODE, new OrganisationUnitCodeComparator() );
+ organisationUnitComparators.put( SORT_ORDER_CUSTOM, new OrganisationUnitNameComparator() ); // SIC
+
+ dataSetComparators = new HashMap<String, Comparator<DataSet>>();
+ dataSetComparators.put( SORT_ORDER_NAME, new DataSetNameComparator() );
+ dataSetComparators.put( SORT_ORDER_SHORTNAME, new DataSetShortNameComparator() );
+ dataSetComparators.put( SORT_ORDER_ALTERNATIVENAME, new DataSetNameComparator() ); // SIC
+ dataSetComparators.put( SORT_ORDER_CODE, new DataSetCodeComparator() );
+ dataSetComparators.put( SORT_ORDER_CUSTOM, new DataSetSortOrderComparator() );
+ }
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
+
private UserSettingService userSettingService;
public void setUserSettingService( UserSettingService userSettingService )
@@ -97,116 +135,22 @@
public Comparator<DataElement> getCurrentDataElementSortOrderComparator()
{
- String sortOrder = getCurrentSortOrder();
-
- if ( sortOrder != null )
- {
- if ( sortOrder.equals( SORT_ORDER_NAME ) )
- {
- return new DataElementNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_SHORTNAME ) )
- {
- return new DataElementShortNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_ALTERNATIVENAME ) )
- {
- return new DataElementAlternativeNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CODE ) )
- {
- return new DataElementCodeComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CUSTOM ) )
- {
- return new DataElementSortOrderComparator();
- }
- }
-
- return new DataElementNameComparator();
+ return dataElementComparators.get( getCurrentSortOrder() );
}
public Comparator<Indicator> getCurrentIndicatorSortOrderComparator()
{
- String sortOrder = getCurrentSortOrder();
-
- if ( sortOrder != null )
- {
- if ( sortOrder.equals( SORT_ORDER_NAME ) )
- {
- return new IndicatorNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_SHORTNAME ) )
- {
- return new IndicatorShortNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_ALTERNATIVENAME ) )
- {
- return new IndicatorAlternativeNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CODE ) )
- {
- return new IndicatorCodeComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CUSTOM ) )
- {
- return new IndicatorSortOrderComparator();
- }
- }
-
- return new IndicatorNameComparator();
+ return indicatorComparators.get( getCurrentSortOrder() );
}
public Comparator<OrganisationUnit> getCurrentOrganisationUnitSortOrderComparator()
{
- String sortOrder = getCurrentSortOrder();
-
- if ( sortOrder != null )
- {
- if ( sortOrder.equals( SORT_ORDER_NAME ) || sortOrder.equals( SORT_ORDER_ALTERNATIVENAME ) )
- {
- return new OrganisationUnitNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_SHORTNAME ) )
- {
- return new OrganisationUnitShortNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CODE ) )
- {
- return new OrganisationUnitCodeComparator();
- }
-
- // Custom sort order not implemented
- }
-
- return new OrganisationUnitNameComparator();
+ return organisationUnitComparators.get( getCurrentSortOrder() );
}
public Comparator<DataSet> getCurrentDataSetSortOrderComparator()
{
- String sortOrder = getCurrentSortOrder();
-
- if ( sortOrder != null )
- {
- if ( sortOrder.equals( SORT_ORDER_NAME ) || sortOrder.equals( SORT_ORDER_ALTERNATIVENAME ) )
- {
- return new DataSetNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_SHORTNAME ) )
- {
- return new DataSetShortNameComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CODE ) )
- {
- return new DataSetCodeComparator();
- }
- if ( sortOrder.equals( SORT_ORDER_CUSTOM ) )
- {
- return new DataSetSortOrderComparator();
- }
- }
-
- return new DataSetNameComparator();
+ return dataSetComparators.get( getCurrentSortOrder() );
}
public List<String> getSortOrders()
=== modified file 'dhis-2/dhis-options/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-options/src/main/resources/META-INF/dhis/beans.xml 2009-09-28 19:33:22 +0000
+++ dhis-2/dhis-options/src/main/resources/META-INF/dhis/beans.xml 2009-10-06 11:29:00 +0000
@@ -5,7 +5,7 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="org.hisp.dhis.options.sortorder.SortOrderManager"
- class="org.hisp.dhis.options.sortorder.DefaultSortOrderManager">
+ class="org.hisp.dhis.options.sortorder.DefaultSortOrderManager" init-method="init">
<property name="userSettingService"
ref="org.hisp.dhis.user.UserSettingService"/>
</bean>