Support Interval#translate and Interval#EMPTY
Closed this issue · 0 comments
glains commented
I would propose to enhance the current Interval
implementation.
First, Interval.EMPTY
, as an addition to the already existing Interval.ALL
. The current approach requires to pass the same interval twice, such as Interval.of(Instant.MIN, Instant.MIN)
.
/**
* An empty interval.
*/
public static final Interval EMPTY = new Interval(Instant.MIN, Instant.MIN);
Secondly, a method to tralslate the current interval using the already existing Duration
class. Take the following example:
Duration translation = Duration.ofMinutes(2);
interval.withStart(interval.getStart().plus(translation))
.withEnd(interval.getEnd().plus(translation));
The given translation can be negative to support either plus or minus.
An implementation might look like this:
public Interval translate(Duration translation) {
requireNonNull(translation, "The translation must not be null");
return new Interval(start.plus(translation), end.plus(translation));
}
One could also check for Duration.isZero()
before and return the same instance.