Merge "Removed unused dependency."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / MinMaxElementsValidation.java
index 306d9c8581233362e07ec61f27500a5680548e85..525ff55612146323284be99d4017a32a95c515ba 100644 (file)
@@ -37,7 +37,7 @@ final class MinMaxElementsValidation extends SchemaAwareApplyOperation {
         this.maxElements = maxElements;
     }
 
-    static final SchemaAwareApplyOperation from(final SchemaAwareApplyOperation delegate, final DataSchemaNode schema) {
+    static SchemaAwareApplyOperation from(final SchemaAwareApplyOperation delegate, final DataSchemaNode schema) {
         final ConstraintDefinition constraints = schema.getConstraints();
         if (constraints == null || (constraints.getMinElements() == null && constraints.getMaxElements() == null)) {
             return delegate;
@@ -46,6 +46,22 @@ final class MinMaxElementsValidation extends SchemaAwareApplyOperation {
 
     }
 
+    private static int findChildrenBefore(final Optional<TreeNode> current) {
+        if (current.isPresent()) {
+            return numOfChildrenFromValue(current.get().getData());
+        } else {
+            return 0;
+        }
+    }
+
+    private static int findChildrenAfter(final ModifiedNode modification) {
+        if (modification.getWrittenValue() != null) {
+            return numOfChildrenFromValue(modification.getWrittenValue());
+        } else {
+            return 0;
+        }
+    }
+
     private void checkMinMaxElements(final YangInstanceIdentifier path, final NodeModification nodeMod,
             final Optional<TreeNode> current) throws DataValidationFailedException {
         if (!(nodeMod instanceof ModifiedNode)) {
@@ -53,19 +69,10 @@ final class MinMaxElementsValidation extends SchemaAwareApplyOperation {
             return;
         }
         final ModifiedNode modification = (ModifiedNode) nodeMod;
-        final int childrenBefore;
-        if (current.isPresent()) {
-            childrenBefore = numOfChildrenFromValue(current.get().getData());
-        } else {
-            childrenBefore = 0;
-        }
 
-        final int childrenAfter;
-        if (modification.getWrittenValue() != null) {
-            childrenAfter = numOfChildrenFromValue(modification.getWrittenValue());
-        } else {
-            childrenAfter = 0;
-        }
+        final int childrenBefore = findChildrenBefore(current);
+
+        final int childrenAfter = findChildrenAfter(modification);
 
         final int childrenTotal = childrenBefore + childrenAfter + numOfChildrenFromChildMods(modification, current);
         if (minElements != null && minElements > childrenTotal) {