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 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;
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;
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");
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);
44 public QName getQName() {
45 return schemaPath.getLastComponent();
50 public SchemaPath getPath() {
55 public Optional<String> getDescription() {
56 return Optional.ofNullable(description);
60 public Optional<String> getReference() {
61 return Optional.ofNullable(reference);
66 public Status getStatus() {
72 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
77 public long getPosition() {
83 public String getName() {
84 return getQName().getLocalName();
88 public int hashCode() {
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();
99 public boolean equals(final Object obj) {
106 if (getClass() != obj.getClass()) {
109 final Bit other = (Bit) obj;
110 return Objects.equals(schemaPath, other.getPath());
114 public String toString() {
115 return Bit.class.getSimpleName() + "[name=" + getQName().getLocalName() + ", position=" + position + "]";