Closed greyhairredbear closed 3 months ago
I can say for certain that a method returning null isn't appropriate for ThreeTen-Extra - I consider null return values to be painful.
The question then becomes whether an Optional
returning method in these use cases adds enough value, and I struggle to see that it does. There is already the isConnected
method, which is little different conceptually to checking the state of the optional.
As such, I'm going to close this as won't fix.
When getting the
intersection
or theunion
of twoInterval
s, I either have to check forisConnected
beforehand or wrap the call inside atry-catch
to avoid aDateTimeException
. Both of these solutionstry-catch
might impact performance, the extraisConnected
call might negligible).That's why I'd like to propose to create a version of these functions which return
null
instead of throwing. I think that this would also make sense in terms of semantics (withnull
implying "there is no such thing" vs. aDateTimeException
implying "you're using this function in the wrong way").My use case to give a bit more context: I'm using
threeten-extra
for solving a Vehicle Routing Problem using Optaplanner/Timefold (that's where the concern regarding performance is stemming from) using Kotlin as programming language (that's where the feeling of "cumbersomeness" is stemming from - Kotlin provides quite nice tools to work with nullable values).I'd also like to understand the reason for implementing
intersection
andunion
this way, since for exampleoverlap
from joda time returnsnull
instead of throwing when there is no overlap between the intervals.Willing to open a PR for this, if this feature is wanted.