*/
package org.opendaylight.yangtools.yang.parser.util;
+import com.google.common.base.Optional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
/**
* Holder object for holding YANG type constraints.
+ *
+ * @deprecated Pre-Beryllium implementation, scheduled for removal.
*/
+@Deprecated
public final class TypeConstraints {
private final String moduleName;
private final int line;
- private final List<List<RangeConstraint>> ranges = new ArrayList<List<RangeConstraint>>();
- private final List<List<LengthConstraint>> lengths = new ArrayList<List<LengthConstraint>>();
- private final List<List<PatternConstraint>> patterns = new ArrayList<List<PatternConstraint>>();
- private final List<Integer> fractionDigits = new ArrayList<Integer>();
+ private final List<List<RangeConstraint>> ranges = new ArrayList<>();
+ private final List<List<LengthConstraint>> lengths = new ArrayList<>();
+ private final List<List<PatternConstraint>> patterns = new ArrayList<>();
+ private final List<Integer> fractionDigits = new ArrayList<>();
public TypeConstraints(final String moduleName, final int line) {
this.moduleName = moduleName;
this.line = line;
}
- List<List<RangeConstraint>> getAllRanges() {
- return ranges;
- }
-
public List<RangeConstraint> getRange() {
if (ranges.size() < 2) {
return Collections.emptyList();
if (max instanceof UnknownBoundaryNumber) {
max = resolveMaxRange(max);
}
- firstRange = BaseConstraints.rangeConstraint(min, max, firstRange.getDescription(),
- firstRange.getReference());
+ firstRange = BaseConstraints.newRangeConstraint(min, max,
+ Optional.fromNullable(firstRange.getDescription()),
+ Optional.fromNullable(firstRange.getReference()));
resolved.set(0, firstRange);
- lastRange = BaseConstraints.rangeConstraint(min, max, lastRange.getDescription(), lastRange.getReference());
+ lastRange = BaseConstraints.newRangeConstraint(min, max,
+ Optional.fromNullable(lastRange.getDescription()),
+ Optional.fromNullable(lastRange.getReference()));
resolved.set(resolved.size() - 1, lastRange);
} else {
if (min instanceof UnknownBoundaryNumber) {
min = resolveMinRange(min);
- firstRange = BaseConstraints.rangeConstraint(min, firstRange.getMax(), firstRange.getDescription(),
- firstRange.getReference());
+ firstRange = BaseConstraints.newRangeConstraint(min, firstRange.getMax(),
+ Optional.fromNullable(firstRange.getDescription()),
+ Optional.fromNullable(firstRange.getReference()));
resolved.set(0, firstRange);
}
if (max instanceof UnknownBoundaryNumber) {
max = resolveMaxRange(max);
- lastRange = BaseConstraints.rangeConstraint(lastRange.getMin(), max, lastRange.getDescription(),
- lastRange.getReference());
+ lastRange = BaseConstraints.newRangeConstraint(lastRange.getMin(), max,
+ Optional.fromNullable(lastRange.getDescription()),
+ Optional.fromNullable(lastRange.getReference()));
resolved.set(resolved.size() - 1, lastRange);
}
}
if (max instanceof UnknownBoundaryNumber) {
max = resolveMaxLength(max);
}
- firstLength = BaseConstraints.lengthConstraint(min, max, firstLength.getDescription(),
- firstLength.getReference());
+ firstLength = BaseConstraints.newLengthConstraint(min, max,
+ Optional.fromNullable(firstLength.getDescription()),
+ Optional.fromNullable(firstLength.getReference()));
resolved.set(0, firstLength);
- lastLength = BaseConstraints.lengthConstraint(min, max, lastLength.getDescription(),
- lastLength.getReference());
+ lastLength = BaseConstraints.newLengthConstraint(min, max,
+ Optional.fromNullable(lastLength.getDescription()),
+ Optional.fromNullable(lastLength.getReference()));
resolved.set(resolved.size() - 1, lastLength);
} else {
if (min instanceof UnknownBoundaryNumber) {
min = resolveMinLength(min);
- firstLength = BaseConstraints.lengthConstraint(min, firstLength.getMax(), firstLength.getDescription(),
- firstLength.getReference());
+ firstLength = BaseConstraints.newLengthConstraint(min, firstLength.getMax(),
+ Optional.fromNullable(firstLength.getDescription()),
+ Optional.fromNullable(firstLength.getReference()));
resolved.set(0, firstLength);
}
if (max instanceof UnknownBoundaryNumber) {
max = resolveMaxLength(max);
- lastLength = BaseConstraints.lengthConstraint(lastLength.getMin(), max, lastLength.getDescription(),
- lastLength.getReference());
+ lastLength = BaseConstraints.newLengthConstraint(lastLength.getMin(), max,
+ Optional.fromNullable(lastLength.getDescription()),
+ Optional.fromNullable(lastLength.getReference()));
resolved.set(resolved.size() - 1, lastLength);
}
}
validateRange(getRange());
}
- private void validateRange(List<RangeConstraint> typeRange) {
+ private void validateRange(final List<RangeConstraint> typeRange) {
if (ranges.size() < 2) {
return;
}
}
}
- private boolean areRangesSubintervalsOfParentRanges(List<RangeConstraint> parentRanges, final BigDecimal min,
+ private boolean areRangesSubintervalsOfParentRanges(final List<RangeConstraint> parentRanges, final BigDecimal min,
final BigDecimal max) {
boolean check = false;
for (RangeConstraint r : parentRanges) {
validateLength(getLength());
}
- private void validateLength(List<LengthConstraint> typeLength) {
+ private void validateLength(final List<LengthConstraint> typeLength) {
if (lengths.size() < 2) {
return;
}