-
New Feature
-
Resolution: Unresolved
-
Medium
-
None
Our current checks currently look like this:
private static final Range<Decimal64>[] CHECK_VALUERANGE_RANGES; static { @SuppressWarnings("unchecked") final Range<Decimal64>[] a = (Range<Decimal64>[]) Array.newInstance(Range.class, 1); a[0] = Range.closed(Decimal64.of(2, 7777L), Decimal64.of(2, 11111L)); CHECK_VALUERANGE_RANGES = a; } private static void check_valueRange(final org.opendaylight.yangtools.yang.common.Decimal64 value) { for (Range<Decimal64> r : CHECK_VALUERANGE_RANGES) { if (r.contains(value)) { return; } } CodeHelpers.throwInvalidRange(CHECK_VALUERANGE_RANGES, value); } @ConstructorParameters("value") @ConstructorProperties("value") public MyDerivedDecimal2(Decimal64 _value) { super(_value); if (_value != null) { check_valueRange(_value); } CodeHelpers.requireValue(_value); }
This has one major omission: we do not check Decimal64.scale(), which should always be matching fraction-digits.
Once we check that, we can also improve performance and memory footprint: if the scale matches, then the range checks can be performed on the unscaled value – i.e. for a similar cost as our uint32/uint64 checks.
Once we are in the area, we should also clean up the layout of the above:
- the requireValue return should be used for field initialization, or
- if we have superclass (as above) it should be omitted
- since we have non-nullness established, there is no need for the if (_value != null) guard
- is blocked by
-
MDSAL-85 Binding Model API: restrictions do not match java type
- Confirmed