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