Propagate @Deprecated annotation
[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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
21
22 public final class BitImpl implements BitsTypeDefinition.Bit, Immutable {
23     private final Long position;
24     private final QName qname;
25     private final SchemaPath schemaPath;
26     private final String description;
27     private final String reference;
28     private final Status status;
29     private final List<UnknownSchemaNode> unknownNodes;
30
31     public BitImpl(final Long position, final QName qname, final SchemaPath schemaPath, final String description,
32             final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
33         this.position = Preconditions.checkNotNull(position, "Position should not be null");
34         this.qname = Preconditions.checkNotNull(qname, "QName should not be null");
35         this.schemaPath = Preconditions.checkNotNull(schemaPath, "Schema Path should not be null");
36         this.description = description;
37         this.reference = reference;
38         this.status = status;
39         if (unknownNodes != null) {
40             this.unknownNodes = unknownNodes;
41         } else {
42             this.unknownNodes = ImmutableList.of();
43         }
44     }
45
46     @Override
47     public QName getQName() {
48         return qname;
49     }
50
51     @Override
52     public SchemaPath getPath() {
53         return schemaPath;
54     }
55
56     @Override
57     public String getDescription() {
58         return description;
59     }
60
61     @Override
62     public String getReference() {
63         return reference;
64     }
65
66     @Override
67     public Status getStatus() {
68         return status;
69     }
70
71     @Override
72     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
73         return unknownNodes;
74     }
75
76     @Override
77     public Long getPosition() {
78         return position;
79     }
80
81     @Override
82     public String getName() {
83         return qname.getLocalName();
84     }
85
86     @Override
87     public int hashCode() {
88         final int prime = 31;
89         int result = 1;
90         result = prime * result + qname.hashCode();
91         result = prime * result + schemaPath.hashCode();
92         result = prime * result + position.hashCode();
93         result = prime * result + unknownNodes.hashCode();
94         return result;
95     }
96
97     @Override
98     public boolean equals(final Object obj) {
99         if (this == obj) {
100             return true;
101         }
102         if (obj == null) {
103             return false;
104         }
105         if (getClass() != obj.getClass()) {
106             return false;
107         }
108         Bit other = (Bit) obj;
109         return Objects.equals(qname, other.getQName()) && Objects.equals(schemaPath, other.getPath());
110     }
111
112     @Override
113     public String toString() {
114         return Bit.class.getSimpleName() + "[name=" + qname.getLocalName() + ", position=" + position + "]";
115     }
116
117 }