[threeten-dev] lambda + threeten

Roger Riggs Roger.Riggs at oracle.com
Mon Dec 3 10:32:02 PST 2012


Hi Sherman,

Its great to see this.

On 12/3/2012 1:22 PM, Xueming Shen wrote:
>
> I experimented the lambda repo + threeten repo to see how much we
> might need to do when lambda stuff gets into the master. While it still
> took couple hours to (lots of emacs editing...) sort everything out, it
> appears it can be done smoothly in hours.
>
> The only issue (not straightforward/simply copy/paste) I found is that
> three j.l.Object methods equals/hashCode/toString can NOT be
> default-method-ed in ChronoLocalD/DT/ODT/ZDT. It appears to be not
> allowed. Sorry, if this is a well-known spec that I'm not aware of , I'm
> a lambda newbie:-) they need to be simply  defined as @override
> method and the (default) impl need to go into their corresponding impl
> classes.
>
> I'm not sure if all those utility methods in "jdk8Methods" have been
> in jdk8, so I did not touch them this time. But at least so of them
> are there already. Should we just migrate?
Yes, as is the github version can be used with JDK 7.
After we commit to mercurial, we can change to the java.math versions.
>
> Here is the java doc for the combined threeten_lambda
>
> http://cr.openjdk.java.net/~sherman/jdk8_threeten/api_lambda/
>
> The webrev/diff for the changes, if interested.
>
> http://cr.openjdk.java.net/~sherman/jdk8_threeten/defaultM
>
> And yes, I have my first lambda + threeten test, and trying Stephen's
> fancy functional interfaces With/MinusAdjuster :-)
>
> I might write a blog for our first lambda+threeten repo/binary.
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