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