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 com.google.common.collect.ImmutableList;
14 import java.util.List;
15 import java.util.Objects;
16 import java.util.Optional;
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 ImmutableList<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 = ImmutableList.copyOf(unknownNodes);
46 public QName getQName() {
47 return schemaPath.getLastComponent();
51 public SchemaPath getPath() {
56 public Optional<String> getDescription() {
57 return Optional.ofNullable(description);
61 public Optional<String> getReference() {
62 return Optional.ofNullable(reference);
66 public Status getStatus() {
71 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
76 public long getPosition() {
81 public String getName() {
82 return getQName().getLocalName();
86 public int hashCode() {
89 result = prime * result + getQName().hashCode();
90 result = prime * result + schemaPath.hashCode();
91 result = prime * result + Long.hashCode(position);
92 result = prime * result + unknownNodes.hashCode();
97 public boolean equals(final Object obj) {
104 if (getClass() != obj.getClass()) {
107 final Bit other = (Bit) obj;
108 return Objects.equals(schemaPath, other.getPath());
112 public String toString() {
113 return Bit.class.getSimpleName() + "[name=" + getQName().getLocalName() + ", position=" + position + "]";