Merge "Direct schema node lookup in SchemaUtils"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / UsesEffectiveStatementImpl.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.rfc6020.effective;
9
10 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
11 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
12
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
15 import com.google.common.collect.ImmutableList;
16 import com.google.common.collect.ImmutableMap;
17 import com.google.common.collect.ImmutableSet;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Set;
21 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
22 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.UsesNode;
26
27 public class UsesEffectiveStatementImpl extends EffectiveStatementBase<QName, UsesStatement>implements UsesNode {
28     private SchemaPath groupingPath;
29     ImmutableSet<AugmentationSchema> augmentations;
30     private boolean addedByUses;
31     ImmutableMap<SchemaPath, SchemaNode> refines;
32     ImmutableList<UnknownSchemaNode> unknownNodes;
33
34     public UsesEffectiveStatementImpl(StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
35         super(ctx);
36
37         this.groupingPath = null;
38     }
39
40     @Override
41     public SchemaPath getGroupingPath() {
42         return groupingPath;
43     }
44
45     @Override
46     public Set<AugmentationSchema> getAugmentations() {
47         return augmentations;
48     }
49
50     @Override
51     public boolean isAugmenting() {
52         return false;
53     }
54
55     @Override
56     public boolean isAddedByUses() {
57         return addedByUses;
58     }
59
60     void setAddedByUses(final boolean addedByUses) {
61         this.addedByUses = addedByUses;
62     }
63
64     @Override
65     public Map<SchemaPath, SchemaNode> getRefines() {
66         return refines;
67     }
68
69     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
70         return unknownNodes;
71     }
72
73     @Override
74     public int hashCode() {
75         final int prime = 31;
76         int result = 1;
77         result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());
78         result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());
79         return result;
80     }
81
82     @Override
83     public boolean equals(final Object obj) {
84         if (this == obj) {
85             return true;
86         }
87         if (obj == null) {
88             return false;
89         }
90         if (getClass() != obj.getClass()) {
91             return false;
92         }
93         final UsesEffectiveStatementImpl other = (UsesEffectiveStatementImpl) obj;
94         if (groupingPath == null) {
95             if (other.groupingPath != null) {
96                 return false;
97             }
98         } else if (!groupingPath.equals(other.groupingPath)) {
99             return false;
100         }
101         if (augmentations == null) {
102             if (other.augmentations != null) {
103                 return false;
104             }
105         } else if (!augmentations.equals(other.augmentations)) {
106             return false;
107         }
108         return true;
109     }
110
111     @Override
112     public String toString() {
113         StringBuilder sb = new StringBuilder(UsesEffectiveStatementImpl.class.getSimpleName());
114         sb.append("[groupingPath=");
115         sb.append(groupingPath);
116         sb.append("]");
117         return sb.toString();
118     }
119 }