Scripted update of if statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / util / TypeConstraints.java
index e3c31966a31b9ee0a6ec32c1145c96f15e2d112e..958d5f280b8e4890735eaa2f7014d23c14719b92 100644 (file)
@@ -7,11 +7,11 @@
  */
 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;
@@ -19,24 +19,23 @@ import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
 
 /**
  * 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();
@@ -62,22 +61,27 @@ public final class TypeConstraints {
             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);
             }
         }
@@ -144,23 +148,27 @@ public final class TypeConstraints {
             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);
             }
         }
@@ -230,7 +238,7 @@ public final class TypeConstraints {
         validateRange(getRange());
     }
 
-    private void validateRange(List<RangeConstraint> typeRange) {
+    private void validateRange(final List<RangeConstraint> typeRange) {
         if (ranges.size() < 2) {
             return;
         }
@@ -250,7 +258,7 @@ public final class TypeConstraints {
         }
     }
 
-    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) {
@@ -278,7 +286,7 @@ public final class TypeConstraints {
         validateLength(getLength());
     }
 
-    private void validateLength(List<LengthConstraint> typeLength) {
+    private void validateLength(final List<LengthConstraint> typeLength) {
         if (lengths.size() < 2) {
             return;
         }