dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22638
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10938: Code simplification
------------------------------------------------------------
revno: 10938
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-05-22 17:57:56 +0200
message:
Code simplification
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.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-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java 2013-05-19 18:49:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java 2013-05-22 15:57:56 +0000
@@ -356,6 +356,11 @@
*/
public String getReportingPeriodName( Date date, I18nFormat format )
{
+ if ( date == null )
+ {
+ return getReportingPeriodName( format );
+ }
+
Period period = getPeriodType().createPeriod( date );
return format.formatPeriod( period );
}
@@ -753,33 +758,33 @@
*/
public static List<Period> getRelativePeriodsFromEnum( RelativePeriodEnum relativePeriod, I18nFormat format, boolean dynamicNames )
{
- Map<RelativePeriodEnum, List<Period>> map = new HashMap<RelativePeriodEnum, List<Period>>();
-
- map.put( RelativePeriodEnum.LAST_MONTH, new RelativePeriods().setReportingMonth( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_BIMONTH, new RelativePeriods().setReportingBimonth( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_QUARTER, new RelativePeriods().setReportingQuarter( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_SIX_MONTH, new RelativePeriods().setLastSixMonth( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.MONTHS_THIS_YEAR, new RelativePeriods().setMonthsThisYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.QUARTERS_THIS_YEAR, new RelativePeriods().setQuartersThisYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.THIS_YEAR, new RelativePeriods().setThisYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.MONTHS_LAST_YEAR, new RelativePeriods().setMonthsLastYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.QUARTERS_LAST_YEAR, new RelativePeriods().setQuartersLastYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_YEAR, new RelativePeriods().setLastYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_5_YEARS, new RelativePeriods().setLast5Years( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_12_MONTHS, new RelativePeriods().setLast12Months( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_3_MONTHS, new RelativePeriods().setLast3Months( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_6_BIMONTHS, new RelativePeriods().setLast6BiMonths( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_4_QUARTERS, new RelativePeriods().setLast4Quarters( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_2_SIXMONTHS, new RelativePeriods().setLast2SixMonths( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.THIS_FINANCIAL_YEAR, new RelativePeriods().setThisFinancialYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_FINANCIAL_YEAR, new RelativePeriods().setLastFinancialYear( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_5_FINANCIAL_YEARS, new RelativePeriods().setLast5FinancialYears( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_WEEK, new RelativePeriods().setLast4Weeks( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_4_WEEKS, new RelativePeriods().setLast4Weeks( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_12_WEEKS, new RelativePeriods().setLast12Weeks( true ).getRelativePeriods( format, dynamicNames ) );
- map.put( RelativePeriodEnum.LAST_52_WEEKS, new RelativePeriods().setLast52Weeks( true ).getRelativePeriods( format, dynamicNames ) );
-
- return map.get( relativePeriod );
+ Map<RelativePeriodEnum, RelativePeriods> map = new HashMap<RelativePeriodEnum, RelativePeriods>();
+
+ map.put( RelativePeriodEnum.LAST_MONTH, new RelativePeriods().setReportingMonth( true ) );
+ map.put( RelativePeriodEnum.LAST_BIMONTH, new RelativePeriods().setReportingBimonth( true ) );
+ map.put( RelativePeriodEnum.LAST_QUARTER, new RelativePeriods().setReportingQuarter( true ) );
+ map.put( RelativePeriodEnum.LAST_SIX_MONTH, new RelativePeriods().setLastSixMonth( true ) );
+ map.put( RelativePeriodEnum.MONTHS_THIS_YEAR, new RelativePeriods().setMonthsThisYear( true ) );
+ map.put( RelativePeriodEnum.QUARTERS_THIS_YEAR, new RelativePeriods().setQuartersThisYear( true ) );
+ map.put( RelativePeriodEnum.THIS_YEAR, new RelativePeriods().setThisYear( true ) );
+ map.put( RelativePeriodEnum.MONTHS_LAST_YEAR, new RelativePeriods().setMonthsLastYear( true ) );
+ map.put( RelativePeriodEnum.QUARTERS_LAST_YEAR, new RelativePeriods().setQuartersLastYear( true ) );
+ map.put( RelativePeriodEnum.LAST_YEAR, new RelativePeriods().setLastYear( true ) );
+ map.put( RelativePeriodEnum.LAST_5_YEARS, new RelativePeriods().setLast5Years( true ) );
+ map.put( RelativePeriodEnum.LAST_12_MONTHS, new RelativePeriods().setLast12Months( true ) );
+ map.put( RelativePeriodEnum.LAST_3_MONTHS, new RelativePeriods().setLast3Months( true ) );
+ map.put( RelativePeriodEnum.LAST_6_BIMONTHS, new RelativePeriods().setLast6BiMonths( true ) );
+ map.put( RelativePeriodEnum.LAST_4_QUARTERS, new RelativePeriods().setLast4Quarters( true ) );
+ map.put( RelativePeriodEnum.LAST_2_SIXMONTHS, new RelativePeriods().setLast2SixMonths( true ) );
+ map.put( RelativePeriodEnum.THIS_FINANCIAL_YEAR, new RelativePeriods().setThisFinancialYear( true ) );
+ map.put( RelativePeriodEnum.LAST_FINANCIAL_YEAR, new RelativePeriods().setLastFinancialYear( true ) );
+ map.put( RelativePeriodEnum.LAST_5_FINANCIAL_YEARS, new RelativePeriods().setLast5FinancialYears( true ) );
+ map.put( RelativePeriodEnum.LAST_WEEK, new RelativePeriods().setLast4Weeks( true ) );
+ map.put( RelativePeriodEnum.LAST_4_WEEKS, new RelativePeriods().setLast4Weeks( true ) );
+ map.put( RelativePeriodEnum.LAST_12_WEEKS, new RelativePeriods().setLast12Weeks( true ) );
+ map.put( RelativePeriodEnum.LAST_52_WEEKS, new RelativePeriods().setLast52Weeks( true ) );
+
+ return map.containsKey( relativePeriod ) ? map.get( relativePeriod ).getRelativePeriods( format, dynamicNames ) : null;
}
/**