- @Override
- protected TreeNode applyWrite(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
- final Version version) {
- final TreeNode validated = modification.getValidatedNode(this, currentMeta);
- if (validated != null) {
- return validated;
+ private void validateMinMaxElements(final ModificationPath path, final NormalizedNode<?, ?> value)
+ throws DataValidationFailedException {
+ final PathArgument id = value.getIdentifier();
+ final int children = numOfChildrenFromValue(value);
+ if (minElements > children) {
+ throw new RequiredElementCountException(path.toInstanceIdentifier(), minElements, maxElements, children,
+ "%s does not have enough elements (%s), needs at least %s", id, children, minElements);
+ }
+ if (maxElements < children) {
+ throw new RequiredElementCountException(path.toInstanceIdentifier(), minElements, maxElements, children,
+ "%s has too many elements (%s), can have at most %s", id, children, maxElements);