Since SchemaAwareApplyOperation exposes underlying schema, we can
make MinMaxElementsValidation require a specific schema type, making
the code a bit simpler.
JIRA: YANGTOOLS-955
Change-Id: I00700d2b45f4163072d8c4d4c364bd8047e5b430
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class MinMaxElementsValidation extends DelegatingModificationApplyOperation {
+final class MinMaxElementsValidation<T extends DataSchemaNode & ElementCountConstraintAware>
+ extends DelegatingModificationApplyOperation {
private static final Logger LOG = LoggerFactory.getLogger(MinMaxElementsValidation.class);
private static final Logger LOG = LoggerFactory.getLogger(MinMaxElementsValidation.class);
- private final SchemaAwareApplyOperation<?> delegate;
+ private final SchemaAwareApplyOperation<T> delegate;
private final int minElements;
private final int maxElements;
private final int minElements;
private final int maxElements;
- private MinMaxElementsValidation(final SchemaAwareApplyOperation<?> delegate, final Integer minElements,
+ private MinMaxElementsValidation(final SchemaAwareApplyOperation<T> delegate, final Integer minElements,
final Integer maxElements) {
this.delegate = requireNonNull(delegate);
this.minElements = minElements != null ? minElements : 0;
this.maxElements = maxElements != null ? maxElements : Integer.MAX_VALUE;
}
final Integer maxElements) {
this.delegate = requireNonNull(delegate);
this.minElements = minElements != null ? minElements : 0;
this.maxElements = maxElements != null ? maxElements : Integer.MAX_VALUE;
}
- static ModificationApplyOperation from(final SchemaAwareApplyOperation<?> delegate, final DataSchemaNode schema) {
- if (!(schema instanceof ElementCountConstraintAware)) {
- return delegate;
- }
- final Optional<ElementCountConstraint> optConstraint = ((ElementCountConstraintAware) schema)
- .getElementCountConstraint();
+ static <T extends DataSchemaNode & ElementCountConstraintAware> ModificationApplyOperation from(
+ final SchemaAwareApplyOperation<T> delegate) {
+ final Optional<ElementCountConstraint> optConstraint = delegate.getSchema().getElementCountConstraint();
if (!optConstraint.isPresent()) {
return delegate;
}
final ElementCountConstraint constraint = optConstraint.get();
if (!optConstraint.isPresent()) {
return delegate;
}
final ElementCountConstraint constraint = optConstraint.get();
- return new MinMaxElementsValidation(delegate, constraint.getMinElements(), constraint.getMaxElements());
+ return new MinMaxElementsValidation<>(delegate, constraint.getMinElements(), constraint.getMaxElements());
} else if (schemaNode instanceof ChoiceSchemaNode) {
return new ChoiceModificationStrategy((ChoiceSchemaNode) schemaNode, treeConfig);
} else if (schemaNode instanceof LeafListSchemaNode) {
} else if (schemaNode instanceof ChoiceSchemaNode) {
return new ChoiceModificationStrategy((ChoiceSchemaNode) schemaNode, treeConfig);
} else if (schemaNode instanceof LeafListSchemaNode) {
- return fromLeafListSchemaNode((LeafListSchemaNode) schemaNode, treeConfig);
+ return MinMaxElementsValidation.from(new LeafSetModificationStrategy((LeafListSchemaNode) schemaNode,
+ treeConfig));
} else if (schemaNode instanceof LeafSchemaNode) {
return new ValueNodeModificationStrategy<>(LeafNode.class, (LeafSchemaNode) schemaNode);
}
} else if (schemaNode instanceof LeafSchemaNode) {
return new ValueNodeModificationStrategy<>(LeafNode.class, (LeafSchemaNode) schemaNode);
}
private static ModificationApplyOperation fromListSchemaNode(final ListSchemaNode schemaNode,
final DataTreeConfiguration treeConfig) {
final List<QName> keyDefinition = schemaNode.getKeyDefinition();
private static ModificationApplyOperation fromListSchemaNode(final ListSchemaNode schemaNode,
final DataTreeConfiguration treeConfig) {
final List<QName> keyDefinition = schemaNode.getKeyDefinition();
- final SchemaAwareApplyOperation<?> op;
+ final SchemaAwareApplyOperation<ListSchemaNode> op;
if (keyDefinition == null || keyDefinition.isEmpty()) {
op = new UnkeyedListModificationStrategy(schemaNode, treeConfig);
} else {
op = MapModificationStrategy.of(schemaNode, treeConfig);
}
if (keyDefinition == null || keyDefinition.isEmpty()) {
op = new UnkeyedListModificationStrategy(schemaNode, treeConfig);
} else {
op = MapModificationStrategy.of(schemaNode, treeConfig);
}
- return MinMaxElementsValidation.from(op, schemaNode);
- }
-
- private static ModificationApplyOperation fromLeafListSchemaNode(final LeafListSchemaNode schemaNode,
- final DataTreeConfiguration treeConfig) {
- return MinMaxElementsValidation.from(new LeafSetModificationStrategy(schemaNode, treeConfig), schemaNode);
+ return MinMaxElementsValidation.from(op);
}
protected static void checkNotConflicting(final ModificationPath path, final TreeNode original,
}
protected static void checkNotConflicting(final ModificationPath path, final TreeNode original,