-
- private static boolean rangeCovered(final List<RangeConstraint> where,
- final RangeConstraint what) {
- for (RangeConstraint c : where) {
- if (NumberUtil.isRangeCovered(what.getMin(), what.getMax(), c.getMin(), c.getMax())) {
- return true;
- }
- }
-
- return false;
- }
-
- final List<RangeConstraint> calculateRangeConstraints(final List<RangeConstraint> baseRangeConstraints) {
- if (rangeAlternatives == null || rangeAlternatives.isEmpty()) {
- return baseRangeConstraints;
- }
-
- // Run through alternatives and resolve them against the base type
- Verify.verify(!baseRangeConstraints.isEmpty(), "Base type %s does not define constraints", getBaseType());
- final List<RangeConstraint> resolvedRanges = ensureResolvedRanges(rangeAlternatives, baseRangeConstraints);
-
- // Next up, ensure the of boundaries match base constraints
- final Class<? extends Number> clazz = baseRangeConstraints.get(0).getMin().getClass();
- final List<RangeConstraint> typedRanges = ensureTypedRanges(resolvedRanges, clazz);
-
- // Now verify if new ranges are strict subset of base ranges
- for (RangeConstraint c : typedRanges) {
- Preconditions.checkArgument(rangeCovered(baseRangeConstraints, c),
- "Range constraint %s is not a subset of parent constraints %s", c, baseRangeConstraints);
- }
-
- // FIXME: merge adjacent ranges and sort them
- return typedRanges;
- }