← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19865: minor fixes, use lambdas for periodcache

 

------------------------------------------------------------
revno: 19865
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-08-27 10:25:46 +0700
message:
  minor fixes, use lambdas for periodcache
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.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/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2015-08-26 07:25:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2015-08-27 03:25:46 +0000
@@ -48,7 +48,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
@@ -62,7 +61,6 @@
     implements Serializable
 {
     // Cache for period lookup, uses calendar.name() + periodType.getName() + date.getTime() as key
-
     private static Cache<String, Period> periodCache = CacheBuilder.newBuilder()
         .expireAfterAccess( 5, TimeUnit.MINUTES )
         .initialCapacity( 10000 )
@@ -245,14 +243,7 @@
     {
         try
         {
-            return periodCache.get( getCacheKey( date ), new Callable<Period>()
-            {
-                @Override
-                public Period call() throws Exception
-                {
-                    return createPeriod( createCalendarInstance( date ) );
-                }
-            } );
+            return periodCache.get( getCacheKey( date ), () -> createPeriod( createCalendarInstance( date ) ) );
         }
         catch ( ExecutionException ignored )
         {
@@ -282,14 +273,7 @@
     {
         try
         {
-            return periodCache.get( getCacheKey( calendar, date ), new Callable<Period>()
-            {
-                @Override
-                public Period call() throws Exception
-                {
-                    return createPeriod( calendar.fromIso( DateTimeUnit.fromJdkDate( date ) ), calendar );
-                }
-            } );
+            return periodCache.get( getCacheKey( calendar, date ), () -> createPeriod( calendar.fromIso( DateTimeUnit.fromJdkDate( date ) ), calendar ) );
         }
         catch ( ExecutionException ignored )
         {
@@ -448,7 +432,7 @@
     /**
      * Returns a list of periods based on the given date string in ISO format.
      *
-     * @param isoPeriod the date string in ISO format.
+     * @param isoPeriods the date strings in ISO format.
      * @return a period.
      */
     public static List<Period> getPeriodsFromIsoStrings( List<String> isoPeriods )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2015-08-26 07:25:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2015-08-27 03:25:46 +0000
@@ -120,9 +120,9 @@
     @Override
     public List<Period> generatePeriods( DateTimeUnit dateTimeUnit )
     {
-        Calendar cal = getCalendar();
+        Calendar calendar = getCalendar();
 
-        dateTimeUnit = cal.minusYears( dateTimeUnit, 5 );
+        dateTimeUnit = calendar.minusYears( dateTimeUnit, 5 );
         dateTimeUnit.setDay( 1 );
         dateTimeUnit.setMonth( 1 );
 
@@ -130,8 +130,8 @@
 
         for ( int i = 0; i < 11; ++i )
         {
-            periods.add( createPeriod( dateTimeUnit, cal ) );
-            dateTimeUnit = cal.plusYears( dateTimeUnit, 1 );
+            periods.add( createPeriod( dateTimeUnit, calendar ) );
+            dateTimeUnit = calendar.plusYears( dateTimeUnit, 1 );
         }
 
         return periods;
@@ -160,10 +160,10 @@
     @Override
     public List<Period> generateLast5Years( Date date )
     {
-        Calendar cal = getCalendar();
+        Calendar calendar = getCalendar();
 
         DateTimeUnit dateTimeUnit = createLocalDateUnitInstance( date );
-        dateTimeUnit = cal.minusYears( dateTimeUnit, 4 );
+        dateTimeUnit = calendar.minusYears( dateTimeUnit, 4 );
         dateTimeUnit.setDay( 1 );
         dateTimeUnit.setMonth( 1 );
 
@@ -171,8 +171,8 @@
 
         for ( int i = 0; i < 5; ++i )
         {
-            periods.add( createPeriod( dateTimeUnit, cal ) );
-            dateTimeUnit = cal.plusYears( dateTimeUnit, 1 );
+            periods.add( createPeriod( dateTimeUnit, calendar ) );
+            dateTimeUnit = calendar.plusYears( dateTimeUnit, 1 );
         }
 
         return periods;
@@ -196,18 +196,17 @@
         return ISO8601_DURATION;
     }
 
-
     @Override
     public Date getRewindedDate( Date date, Integer rewindedPeriods )
     {
-        Calendar cal = getCalendar();
+        Calendar calendar = getCalendar();
 
         date = date != null ? date : new Date();
         rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
 
         DateTimeUnit dateTimeUnit = createLocalDateUnitInstance( date );
-        dateTimeUnit = cal.minusYears( dateTimeUnit, rewindedPeriods );
+        dateTimeUnit = calendar.minusYears( dateTimeUnit, rewindedPeriods );
 
-        return cal.toIso( dateTimeUnit ).toJdkDate();
+        return calendar.toIso( dateTimeUnit ).toJdkDate();
     }
 }