Merge "Introduce Identifiables"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / util / BitImpl.java
1 /*
2  * Copyright (c) 2013 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.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
20
21 final class BitImpl implements BitsTypeDefinition.Bit, Immutable {
22     private final Long position;
23     private final QName qname;
24     private final SchemaPath schemaPath;
25     private final String description;
26     private final String reference;
27     private final Status status;
28     private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
29
30     BitImpl(final Long position, final QName qname, final SchemaPath schemaPath, final String description,
31             final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
32         this.position = position;
33         this.qname = qname;
34         this.schemaPath = schemaPath;
35         this.description = description;
36         this.reference = reference;
37         this.status = status;
38         if (unknownNodes != null) {
39             this.unknownNodes = unknownNodes;
40         }
41     }
42
43     @Override
44     public QName getQName() {
45         return qname;
46     }
47
48     @Override
49     public SchemaPath getPath() {
50         return schemaPath;
51     }
52
53     @Override
54     public String getDescription() {
55         return description;
56     }
57
58     @Override
59     public String getReference() {
60         return reference;
61     }
62
63     @Override
64     public Status getStatus() {
65         return status;
66     }
67
68     @Override
69     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
70         return unknownNodes;
71     }
72
73     @Override
74     public Long getPosition() {
75         return position;
76     }
77
78     @Override
79     public String getName() {
80         return qname.getLocalName();
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = 1;
87         result = prime * result + ((qname == null) ? 0 : qname.hashCode());
88         result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
89         result = prime * result + ((position == null) ? 0 : position.hashCode());
90         result = prime * result + ((unknownNodes == null) ? 0 : unknownNodes.hashCode());
91         return result;
92     }
93
94     @Override
95     public boolean equals(Object obj) {
96         if (this == obj) {
97             return true;
98         }
99         if (obj == null) {
100             return false;
101         }
102         if (getClass() != obj.getClass()) {
103             return false;
104         }
105         Bit other = (Bit) obj;
106         if (qname == null) {
107             if (other.getQName() != null) {
108                 return false;
109             }
110         } else if (!qname.equals(other.getQName())) {
111             return false;
112         }
113         if (schemaPath == null) {
114             if (other.getPath() != null) {
115                 return false;
116             }
117         } else if (!schemaPath.equals(other.getPath())) {
118             return false;
119         }
120         return true;
121     }
122
123     @Override
124     public String toString() {
125         return Bit.class.getSimpleName() + "[name=" + qname.getLocalName() + ", position=" + position + "]";
126     }
127
128 }