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.yangtools.yang.data.impl.schema.tree;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 final class InMemoryDataTreeSnapshot implements DataTreeSnapshot {
20 private final RootModificationApplyOperation applyOper;
21 private final SchemaContext schemaContext;
22 private final TreeNode rootNode;
24 InMemoryDataTreeSnapshot(final SchemaContext schemaContext, final TreeNode rootNode,
25 final RootModificationApplyOperation applyOper) {
26 this.schemaContext = Preconditions.checkNotNull(schemaContext);
27 this.rootNode = Preconditions.checkNotNull(rootNode);
28 this.applyOper = Preconditions.checkNotNull(applyOper);
31 TreeNode getRootNode() {
35 SchemaContext getSchemaContext() {
40 public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
41 return NormalizedNodes.findNode(rootNode.getData(), path);
45 public InMemoryDataTreeModification newModification() {
46 return new InMemoryDataTreeModification(this, applyOper);
50 public String toString() {
51 return rootNode.getSubtreeVersion().toString();