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