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;
}
+ 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)) {
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) {