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