Make SchemaNode.getPath() implementations as deprecated
[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 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;
22
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;
30
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);
40     }
41
42     @Override
43     public Optional<String> getDescription() {
44         return Optional.ofNullable(description);
45     }
46
47     @Override
48     public Optional<String> getReference() {
49         return Optional.ofNullable(reference);
50     }
51
52     @Override
53     public Status getStatus() {
54         return status;
55     }
56
57     @Override
58     public Collection<? extends UnknownSchemaNode> getUnknownSchemaNodes() {
59         return unknownNodes;
60     }
61
62     @Override
63     public long getPosition() {
64         return position;
65     }
66
67     @Override
68     public String getName() {
69         return name;
70     }
71
72     @Override
73     public int hashCode() {
74         return 31 * name.hashCode() + Long.hashCode(position);
75     }
76
77     @Override
78     public boolean equals(final Object obj) {
79         if (this == obj) {
80             return true;
81         }
82         if (!(obj instanceof Bit)) {
83             return false;
84         }
85         final Bit other = (Bit) obj;
86         return name.equals(other.getName()) && position == other.getPosition();
87     }
88
89     @Override
90     public String toString() {
91         return Bit.class.getSimpleName() + "[name=" + name + ", position=" + position + "]";
92     }
93 }