2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util.type;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
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;
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;
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");
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);
47 public QName getQName() {
48 return schemaPath.getLastComponent();
53 public SchemaPath getPath() {
58 public Optional<String> getDescription() {
59 return Optional.ofNullable(description);
63 public Optional<String> getReference() {
64 return Optional.ofNullable(reference);
68 public Status getStatus() {
73 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
78 public long getPosition() {
84 public String getName() {
85 return getQName().getLocalName();
89 public int hashCode() {
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();
100 public boolean equals(final Object obj) {
107 if (getClass() != obj.getClass()) {
110 final Bit other = (Bit) obj;
111 return Objects.equals(schemaPath, other.getPath());
115 public String toString() {
116 return Bit.class.getSimpleName() + "[name=" + getQName().getLocalName() + ", position=" + position + "]";