[threeten-dev] lambda + threeten

Xueming Shen xueming.shen at oracle.com
Mon Dec 3 10:48:41 PST 2012


It's the test for the "fancy" functional interface :-) for example, for
the "minus adjuster" here you can simply use

                .map(d -> (d.minusDays(days)))
instead of
                .map(d -> (d.minus(dd -> (dd.with(EPOCH_DAY, (dd.getLong(EPOCH_DAY)- days))))))

And the test does nothing:-) it simply adds two days, print them out, and then
map them back to the original data.

-Sherman


On 12/03/2012 10:32 AM, Roger Riggs wrote:
> Hi Sherman,
>
>
> I don't know what the non-lambda code would look like but the lambda'fied
> code below is not good at revealing what the intent of the function is.
> It still needs comments.  So blog away.
>
> Thanks,Roger
>
>>
>> -Sherman
>>
>> --------------------------------------------------------------------
>>         LocalDateTime now = LocalDateTime.now();
>>         Random r = new Random();
>>
>>         DateTimeFormatter fmt =
>>             DateTimeFormatters.pattern("yyyy-MM-dd HH:mm:ss [EEEE]");
>>
>>         int total = 100;
>>         int days = 2;     // days to delay
>>         int minMon = 2;
>>         int maxMon = 6;
>>
>>         Streams.repeatedly(total, () -> (now.withYear(2012)
>>                                             .withDayOfYear(r.nextInt(365) + 1)
>>                                             .with(SECOND_OF_DAY, r.nextInt(86400))))
>>                .sorted((d1, d2) -> d1.compareTo(d2))
>> //             .filter(d -> (d.getMonthValue() >= minMon && d.getMonthValue() <= maxMon))
>>                .tee(d -> {System.out.printf(" %-30s ", fmt.print(d));})
>>                .map(d -> (d.with(dd -> (dd.with(EPOCH_DAY, dd.getLong(EPOCH_DAY) + days)))))
>>                .tee(d -> {System.out.printf(" -->   %-30s ", fmt.print(d));})
>>                .map(d -> (d.minus(dd -> (dd.with(EPOCH_DAY, (dd.getLong(EPOCH_DAY)- days))))))
>>                .forEach(d -> {System.out.printf(" -->   %-30s%n", fmt.print(d));});
>>
>
> -- 
> Thanks, Roger
>
> Oracle Java Platform Group
>
> Green Oracle <http://www.oracle.com/commitment> Oracle is committed to developing practices and products that help protect the environment
>



More information about the threeten-dev mailing list