[threeten-dev] lambda + threeten
Xueming Shen
xueming.shen at oracle.com
Mon Dec 3 10:22:58 PST 2012
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?
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.
-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));});
More information about the threeten-dev
mailing list