import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
+final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation<ListSchemaNode> {
+ private static final NormalizedNodeContainerSupport<NodeIdentifier, UnkeyedListEntryNode> ITEM_SUPPORT =
+ new NormalizedNodeContainerSupport<>(UnkeyedListEntryNode.class,
+ ImmutableUnkeyedListEntryNodeBuilder::create, ImmutableUnkeyedListEntryNodeBuilder::create);
- private final Optional<ModificationApplyOperation> entryStrategy;
+ private final DataNodeContainerModificationStrategy<ListSchemaNode> entryStrategy;
private final UnkeyedListNode emptyNode;
UnkeyedListModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
- entryStrategy = Optional.of(new UnkeyedListItemModificationStrategy(schema, treeConfig));
+ entryStrategy = new DataNodeContainerModificationStrategy<>(ITEM_SUPPORT, schema, treeConfig);
emptyNode = ImmutableNodes.listNode(schema.getQName());
}
@Override
- Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> storeMeta,
- final Version version) {
- return AutomaticLifecycleMixin.apply(super::apply, this::applyWrite, emptyNode, modification, storeMeta,
- version);
+ ListSchemaNode getSchema() {
+ return entryStrategy.getSchema();
}
@Override
- void checkApplicable(final ModificationPath path, final NodeModification modification,
- final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
- AutomaticLifecycleMixin.checkApplicable(super::checkApplicable, emptyNode, path, modification, current,
+ Optional<? extends TreeNode> apply(final ModifiedNode modification, final Optional<? extends TreeNode> storeMeta,
+ final Version version) {
+ return AutomaticLifecycleMixin.apply(super::apply, this::applyWrite, emptyNode, modification, storeMeta,
version);
}
@Override
protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
- final Optional<TreeNode> currentMeta, final Version version) {
+ final Optional<? extends TreeNode> currentMeta, final Version version) {
final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
if (modification.getChildren().isEmpty()) {
return newValueMeta;
for (final ModifiedNode mod : modifications) {
final PathArgument id = mod.getIdentifier();
- final Optional<TreeNode> cm = meta.getChild(id);
+ final Optional<? extends TreeNode> cm = meta.getChild(id);
- final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
+ final Optional<? extends TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
if (result.isPresent()) {
final TreeNode tn = result.get();
meta.addChild(tn);
@Override
public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
- return child instanceof NodeIdentifier ? entryStrategy : Optional.empty();
+ return child instanceof NodeIdentifier ? Optional.of(entryStrategy) : Optional.empty();
}
@Override
- protected void verifyStructure(final NormalizedNode<?, ?> writtenValue, final boolean verifyChildren) {
-
+ void verifyValue(final NormalizedNode<?, ?> value) {
+ // NOOP
}
@Override
@Override
protected void checkTouchApplicable(final ModificationPath path, final NodeModification modification,
- final Optional<TreeNode> current, final Version version) throws IncorrectDataStructureException {
+ final Optional<? extends TreeNode> current, final Version version) throws IncorrectDataStructureException {
throw new IncorrectDataStructureException(path.toInstanceIdentifier(), "Subtree modification is not allowed.");
}