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.Collection;
15 import java.util.List;
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.model.api.Status;
20 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
23 final class BitImpl implements Bit, Immutable {
24 private final @NonNull ImmutableList<UnknownSchemaNode> unknownNodes;
25 private final @NonNull String name;
26 private final String description;
27 private final String reference;
28 private final @NonNull Status status;
29 private final long position;
31 BitImpl(final String name, final long position, final String description,
32 final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
33 this.name = requireNonNull(name);
34 checkArgument(position >= 0L && position <= 4294967295L, "Invalid position %s", position);
35 this.position = position;
36 this.description = description;
37 this.reference = reference;
38 this.status = requireNonNull(status);
39 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
43 public Optional<String> getDescription() {
44 return Optional.ofNullable(description);
48 public Optional<String> getReference() {
49 return Optional.ofNullable(reference);
53 public Status getStatus() {
58 public Collection<? extends UnknownSchemaNode> getUnknownSchemaNodes() {
63 public long getPosition() {
68 public String getName() {
73 public int hashCode() {
74 return 31 * name.hashCode() + Long.hashCode(position);
78 public boolean equals(final Object obj) {
82 if (!(obj instanceof Bit)) {
85 final Bit other = (Bit) obj;
86 return name.equals(other.getName()) && position == other.getPosition();
90 public String toString() {
91 return Bit.class.getSimpleName() + "[name=" + name + ", position=" + position + "]";