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 javax.annotation.Nonnull;
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 final class DataSchemaContextTree {
19 private static final LoadingCache<SchemaContext, DataSchemaContextTree> TREES = CacheBuilder.newBuilder()
20 .weakKeys().weakValues().build(new CacheLoader<SchemaContext, DataSchemaContextTree>() {
22 public DataSchemaContextTree load(@Nonnull final SchemaContext key) throws Exception {
23 return new DataSchemaContextTree(key);
27 private final DataSchemaContextNode<?> root;
29 private DataSchemaContextTree(final SchemaContext ctx) {
30 root = DataSchemaContextNode.from(ctx);
33 @Nonnull public static DataSchemaContextTree from(@Nonnull final SchemaContext ctx) {
34 return TREES.getUnchecked(ctx);
37 public DataSchemaContextNode<?> getChild(final YangInstanceIdentifier path) {
38 DataSchemaContextNode<?> currentOp = root;
39 for (PathArgument arg : path.getPathArguments()) {
40 currentOp = currentOp.getChild(arg);
45 public DataSchemaContextNode<?> getRoot() {