[threeten-dev] lambda + threeten
Xueming Shen
xueming.shen at oracle.com
Mon Dec 3 18:14:06 PST 2012
We do have LocalDateTime.minusDays(long) to return LDT. Where does the
DateTime
come from. It appears all three work.
"fluent" .map(d -> (d.minusDays(days)))
long, field .map(d -> (d.minus(days, DAYS)))
minusAdjuster .map(d -> (d.minus(dd -> (dd.with(EPOCH_DAY,
(dd.getLong(EPOCH_DAY)- days))))))
One of the reasons that I thought the API provides too many ways to do
the same thing.
-sherman
On 12/3/12 4:40 PM, Stephen Colebourne wrote:
> .map(d -> (d.minusDays(days)))
> would not work (as the type is DateTime), but this will work:
> .map(d -> (d.minus(days, DAYS)))
>
> It would be worth exploring if generics could be added to
> WithAdjuster/MinusAdjuster etc to allow lambda adjusters to capture
> the actual target type, and thus allow methods like minusDays() to be
> called. I suspect it doesn't work, but it should be tried.
>
> Stephen
>
>
> On 3 December 2012 18:48, Xueming Shen <xueming.shen at oracle.com
> <mailto:xueming.shen at oracle.com>> wrote:
>
>
> 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