f7edfe22cf665bb6c951ae4cf1e5c989d12a469b
[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         this.position = Preconditions.checkNotNull(position, "Position should not be null");
32         this.description = description;
33         this.reference = reference;
34         this.status = Preconditions.checkNotNull(status);
35         this.unknownNodes = Preconditions.checkNotNull(unknownNodes);
36     }
37
38     @Override
39     public QName getQName() {
40         return schemaPath.getLastComponent();
41     }
42
43     @Override
44     public SchemaPath getPath() {
45         return schemaPath;
46     }
47
48     @Override
49     public String getDescription() {
50         return description;
51     }
52
53     @Override
54     public String getReference() {
55         return reference;
56     }
57
58     @Override
59     public Status getStatus() {
60         return status;
61     }
62
63     @Override
64     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
65         return unknownNodes;
66     }
67
68     @Override
69     public Long getPosition() {
70         return position;
71     }
72
73     @Override
74     public String getName() {
75         return getQName().getLocalName();
76     }
77
78     @Override
79     public int hashCode() {
80         final int prime = 31;
81         int result = 1;
82         result = prime * result + getQName().hashCode();
83         result = prime * result + schemaPath.hashCode();
84         result = prime * result + position.hashCode();
85         result = prime * result + unknownNodes.hashCode();
86         return result;
87     }
88
89     @Override
90     public boolean equals(final Object obj) {
91         if (this == obj) {
92             return true;
93         }
94         if (obj == null) {
95             return false;
96         }
97         if (getClass() != obj.getClass()) {
98             return false;
99         }
100         Bit other = (Bit) obj;
101         return Objects.equals(schemaPath, other.getPath());
102     }
103
104     @Override
105     public String toString() {
106         return Bit.class.getSimpleName() + "[name=" + getQName().getLocalName() + ", position=" + position + "]";
107     }
108
109 }