Java Reference
In-Depth Information
need. In fact, the TemporalAdjuster interface declares only a single method (this makes it a
functional interface), defined as follows.
Listing 12.9. The TemporalAdjuster interface
@FunctionalInterface
public interface TemporalAdjuster {
Temporal adjustInto(Temporal temporal);
}
This means an implementation of the TemporalAdjuster interface defines how to convert a
Temporal object into another Temporal. You can think of it as being like a
UnaryOperator<Temporal>. Take a few minutes to practice what you've learned so far and
implement your own TemporalAdjuster in Quiz 12.2 .
Quiz 12.2: Implementing a custom TemporalAdjuster
Develop a class named NextWorkingDay, implementing the TemporalAdjuster interface that
moves a date forward by one day but skips Saturdays and Sundays. Doing the following
date = date.with(new NextWorkingDay());
should move the date to the next day, if this day is between Monday and Friday, but to the next
Monday if it's a Saturday or a Sunday.
Answer:
You can implement the NextWorkingDay adjuster as follows:
Search WWH ::




Custom Search