4507c853e325eb145be8072e2abe22fc7f170051
[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.Objects;
16 import java.util.Set;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.UsesNode;
22
23 final class UsesNodeImpl implements UsesNode {
24     private final SchemaPath groupingPath;
25     ImmutableSet<AugmentationSchema> augmentations;
26     private boolean addedByUses;
27     ImmutableMap<SchemaPath, SchemaNode> refines;
28     ImmutableList<UnknownSchemaNode> unknownNodes;
29
30     UsesNodeImpl(final SchemaPath groupingPath) {
31         this.groupingPath = groupingPath;
32     }
33
34     @Override
35     public SchemaPath getGroupingPath() {
36         return groupingPath;
37     }
38
39     @Override
40     public Set<AugmentationSchema> getAugmentations() {
41         return augmentations;
42     }
43
44     @Override
45     public boolean isAugmenting() {
46         return false;
47     }
48
49     @Override
50     public boolean isAddedByUses() {
51         return addedByUses;
52     }
53
54     void setAddedByUses(final boolean addedByUses) {
55         this.addedByUses = addedByUses;
56     }
57
58     @Override
59     public Map<SchemaPath, SchemaNode> getRefines() {
60         return refines;
61     }
62
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 + Objects.hashCode(groupingPath);
72         result = prime * result + Objects.hashCode(augmentations);
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 }