Is there any standard Java implementation to represent a time range with FROM and TO? Actually I am using the following class.
I also looked at Instant.range() or Period, which are both not defining a time range or span, but calculating the duration of a period instead of saving the exact time range with FROM and TO.
public class TimeRange { private Instant from, to; public TimeRange(Instant from, Instant to) { this.from = from; this.to = to; } public Instant getFrom() { return from; } public void setFrom(Instant from) { this.from = from; } public Instant getTo() { return to; } public void setTo(Instant to) { this.to = to; } public boolean isProperlySet() { return from != null && to != null; } }
isProperlySet()weird. Are you doing this for every object, that contains settable members? Why not just throwing or let throw anException?Instants in the constructor, e.g.this.from = Objects.requireNonNull(from);.