dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29653
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15000: minor change, use map to speed up calendar lookups
------------------------------------------------------------
revno: 15000
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-04-26 14:31:55 +0545
message:
minor change, use map to speed up calendar lookups
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.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-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java 2014-04-25 13:14:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java 2014-04-26 08:46:55 +0000
@@ -29,13 +29,16 @@
*/
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.hisp.dhis.calendar.impl.Iso8601Calendar;
import org.hisp.dhis.setting.SystemSettingManager;
import org.springframework.beans.factory.annotation.Autowired;
+import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -49,10 +52,21 @@
@Autowired
private Set<Calendar> calendars = Sets.newHashSet();
+ private Map<String, Calendar> calendarMap = Maps.newHashMap();
+
+ @PostConstruct
+ public void init()
+ {
+ for ( Calendar calendar : calendars )
+ {
+ calendarMap.put( calendar.name(), calendar );
+ }
+ }
+
@Override
public List<Calendar> getAll()
{
- List<Calendar> sortedCalendars = Lists.newArrayList( calendars );
+ List<Calendar> sortedCalendars = Lists.newArrayList( calendarMap.values() );
Collections.sort( sortedCalendars, CalendarComparator.INSTANCE );
return sortedCalendars;
}
@@ -60,14 +74,11 @@
@Override
public Calendar getSystemCalendar()
{
- String setting = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_CALENDAR, SystemSettingManager.DEFAULT_CALENDAR );
+ String calendar = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_CALENDAR, SystemSettingManager.DEFAULT_CALENDAR );
- for ( Calendar calendar : calendars )
+ if ( calendarMap.containsKey( calendar ) )
{
- if ( setting.equals( calendar.name() ) )
- {
- return calendar;
- }
+ return calendarMap.get( calendar );
}
return Iso8601Calendar.getInstance();