Closed jodastephen closed 11 years ago
It would be more direct to just add Temporal.isSupported(Unit)
similar to TemporalAccessor.isSupported(field)
.
The suggested query is a poor choice as it would require allocating objects and using an expensive contains operation for a function that the Temporal already has direct knowledge of. It also would require explicitly listing of units that may derived from other units.
Adding isSupported(unit)
instead seems OK to me.
Patch ready for review https://gist.github.com/jodastephen/5901479
With respect to isSupported(null) is it more useful to return false than to throw NPE? Otherwise it looks ok to me.
There is a general principle in 310 that we throw NPE in all methods taking an argument except those "is" methods returning a boolean. Same as Object.equals(null).
Issue #312 mvoes part way to enhancing
TemporalUnit.isSupportedBy
, but that method is still poor and not up to standard.If we add
TemporalQuery.supportedUnits()
as a query returningChronoUnit[]
then we can change to this in ChronoUnit:There would be no default method and other units would have to derive from ChronoUnits.