2 * Copyright (c) 2015 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.util;
10 import com.google.common.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import java.util.Iterator;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 public class DataSchemaContextTree {
20 private static final LoadingCache<SchemaContext, DataSchemaContextTree> TREES = CacheBuilder.newBuilder()
22 .build(new CacheLoader<SchemaContext, DataSchemaContextTree>() {
25 public DataSchemaContextTree load(SchemaContext key) throws Exception {
26 return new DataSchemaContextTree(key);
31 private final DataSchemaContextNode<?> root;
33 private DataSchemaContextTree(final SchemaContext ctx) {
34 root = DataSchemaContextNode.from(ctx);
38 public static DataSchemaContextTree from(SchemaContext ctx) {
39 return TREES.getUnchecked(ctx);
42 public DataSchemaContextNode<?> getChild(final YangInstanceIdentifier path) {
43 DataSchemaContextNode<?> currentOp = root;
44 Iterator<PathArgument> arguments = path.getPathArguments().iterator();
45 while (arguments.hasNext()) {
46 currentOp = currentOp.getChild(arguments.next());
51 public DataSchemaContextNode<?> getRoot() {