package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
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.api.schema.tree.spi.TreeNodeFactory;
private final Optional<ModificationApplyOperation> entryStrategy;
- protected UnkeyedListModificationStrategy(final ListSchemaNode schema) {
- entryStrategy = Optional.<ModificationApplyOperation> of(new DataNodeContainerModificationStrategy.UnkeyedListItemModificationStrategy(schema));
+ UnkeyedListModificationStrategy(final ListSchemaNode schema, final TreeType treeType) {
+ entryStrategy = Optional.<ModificationApplyOperation> of(new UnkeyedListItemModificationStrategy(schema, treeType));
}
@Override
- boolean isOrdered() {
- return true;
+ protected ChildTrackingPolicy getChildPolicy() {
+ return ChildTrackingPolicy.ORDERED;
}
@Override
- protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
- final Version version) {
- return applyWrite(modification, Optional.of(currentMeta), version);
+ protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
+ throw new IllegalStateException(String.format("Merge of modification %s on unkeyed list should never be called",
+ modification));
}
@Override
- protected TreeNode applySubtreeChange(final ModifiedNode modification,
+ protected TreeNode applyTouch(final ModifiedNode modification,
final TreeNode currentMeta, final Version version) {
throw new UnsupportedOperationException("UnkeyedList does not support subtree change.");
}
final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
- if (Iterables.isEmpty(modification.getChildren())) {
+ if (modification.getChildren().isEmpty()) {
return newValueMeta;
}
private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data,
final Version nodeVersion, final Iterable<ModifiedNode> modifications) {
- for (ModifiedNode mod : modifications) {
+ for (final ModifiedNode mod : modifications) {
final PathArgument id = mod.getIdentifier();
final Optional<TreeNode> cm = meta.getChild(id);
- Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
+ final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
if (result.isPresent()) {
final TreeNode tn = result.get();
meta.addChild(tn);
}
@Override
- protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+ protected void verifyStructure(final NormalizedNode<?, ?> writtenValue, final boolean verifyChildren) {
}
@Override
- protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
- final Optional<TreeNode> current) throws IncorrectDataStructureException {
+ void recursivelyVerifyStructure(NormalizedNode<?, ?> value) {
+ // NOOP
+ }
+
+ @Override
+ protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+ final Optional<TreeNode> current, final Version version) throws IncorrectDataStructureException {
throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
}
-}
\ No newline at end of file
+
+ @Override
+ void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+ // Unkeyed lists are always replaced
+ node.write(value);
+ }
+}