Update DataTreeFactory
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / EffectiveSchemaContext.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
9
10 import com.google.common.annotations.VisibleForTesting;
11 import com.google.common.base.Verify;
12 import com.google.common.collect.ImmutableList;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Set;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
20 import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
21
22 @VisibleForTesting
23 public final class EffectiveSchemaContext extends SimpleSchemaContext {
24     private final List<DeclaredStatement<?>> rootDeclaredStatements;
25     private final List<EffectiveStatement<?, ?>> rootEffectiveStatements;
26
27     private EffectiveSchemaContext(final Set<Module> modules, final List<DeclaredStatement<?>> rootDeclaredStatements,
28             final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
29         super(modules);
30         this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
31         this.rootEffectiveStatements = ImmutableList.copyOf(rootEffectiveStatements);
32     }
33
34     static EffectiveSchemaContext create(final List<DeclaredStatement<?>> rootDeclaredStatements,
35             final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
36         final Set<Module> modules = new HashSet<>();
37         for (EffectiveStatement<?, ?> stmt : rootEffectiveStatements) {
38             if (stmt.getDeclared() instanceof ModuleStatement) {
39                 Verify.verify(stmt instanceof Module);
40                 modules.add((Module) stmt);
41             }
42         }
43
44         return new EffectiveSchemaContext(modules, rootDeclaredStatements, rootEffectiveStatements);
45     }
46
47     @VisibleForTesting
48     public List<DeclaredStatement<?>> getRootDeclaredStatements() {
49         return rootDeclaredStatements;
50     }
51
52     @VisibleForTesting
53     public List<EffectiveStatement<?, ?>> getRootEffectiveStatements() {
54         return rootEffectiveStatements;
55     }
56 }