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