2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.dom.store.impl.tree.data;
10 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import com.google.common.base.Optional;
14 import com.google.common.primitives.UnsignedLong;
16 final class OperationWithModification {
18 private final NodeModification modification;
20 private final ModificationApplyOperation applyOperation;
22 private OperationWithModification(final ModificationApplyOperation op, final NodeModification mod) {
23 this.modification = mod;
24 this.applyOperation = op;
27 public OperationWithModification write(final NormalizedNode<?, ?> value) {
28 modification.write(value);
29 applyOperation.verifyStructure(modification);
33 public OperationWithModification delete() {
34 modification.delete();
38 public NodeModification getModification() {
42 public ModificationApplyOperation getApplyOperation() {
43 return applyOperation;
46 public Optional<StoreMetadataNode> apply(final Optional<StoreMetadataNode> data, final UnsignedLong subtreeVersion) {
47 return applyOperation.apply(modification, data, subtreeVersion);
50 public static OperationWithModification from(final ModificationApplyOperation operation,
51 final NodeModification modification) {
52 return new OperationWithModification(operation, modification);
56 public void merge(final NormalizedNode<?, ?> data) {
57 modification.merge(data);
58 applyOperation.verifyStructure(modification);
62 public OperationWithModification forChild(final PathArgument childId) {
63 NodeModification childMod = modification.modifyChild(childId);
64 Optional<ModificationApplyOperation> childOp = applyOperation.getChild(childId);
65 return from(childOp.get(),childMod);