Move SchemaNodeIdentifier to yang-common
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / uses / FullCopiedUsesEffectiveStatement.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.rfc7950.stmt.uses;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.Map;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.SchemaNodeIdentifier.Descendant;
15 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
16 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
20
21 /**
22  * A full-blown instance of {@link UsesEffectiveStatement}. Used when the argument does not match the declared instance
23  * and we also have a refine substatement.
24  *
25  */
26 final class FullCopiedUsesEffectiveStatement extends SimpleCopiedUsesEffectiveStatement {
27     private volatile Map<Descendant, SchemaNode> refines;
28
29     FullCopiedUsesEffectiveStatement(final UsesStatement declared, final QName argument,
30             final GroupingDefinition sourceGrouping, final int flags,
31             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
32         super(declared, argument, sourceGrouping, flags, substatements);
33     }
34
35     @Override
36     public Map<Descendant, SchemaNode> getRefines() {
37         final Map<Descendant, SchemaNode> local;
38         return (local = refines) != null ? local : loadRefines();
39     }
40
41     private synchronized @NonNull Map<Descendant, SchemaNode> loadRefines() {
42         Map<Descendant, SchemaNode> local = refines;
43         if (local == null) {
44             refines = local = UsesStatementSupport.indexRefines(effectiveSubstatements());
45         }
46         return local;
47     }
48 }