Populate model/ hierarchy
[yangtools.git] / model / yang-model-ri / src / main / java / org / opendaylight / yangtools / yang / model / ri / 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.ri.type;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableList;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Optional;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.concepts.Immutable;
18 import org.opendaylight.yangtools.yang.common.Uint32;
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 @NonNull Uint32 position;
30
31     BitImpl(final String name, final Uint32 position, final String description,
32             final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
33         this.name = requireNonNull(name);
34         this.position = requireNonNull(position);
35         this.description = description;
36         this.reference = reference;
37         this.status = requireNonNull(status);
38         this.unknownNodes = ImmutableList.copyOf(unknownNodes);
39     }
40
41     @Override
42     public Optional<String> getDescription() {
43         return Optional.ofNullable(description);
44     }
45
46     @Override
47     public Optional<String> getReference() {
48         return Optional.ofNullable(reference);
49     }
50
51     @Override
52     public Status getStatus() {
53         return status;
54     }
55
56     @Override
57     public Collection<? extends UnknownSchemaNode> getUnknownSchemaNodes() {
58         return unknownNodes;
59     }
60
61     @Override
62     public Uint32 getPosition() {
63         return position;
64     }
65
66     @Override
67     public String getName() {
68         return name;
69     }
70
71     @Override
72     public int hashCode() {
73         return 31 * name.hashCode() + position.hashCode();
74     }
75
76     @Override
77     public boolean equals(final Object obj) {
78         if (this == obj) {
79             return true;
80         }
81         if (!(obj instanceof Bit)) {
82             return false;
83         }
84         final Bit other = (Bit) obj;
85         return name.equals(other.getName()) && position == other.getPosition();
86     }
87
88     @Override
89     public String toString() {
90         return Bit.class.getSimpleName() + "[name=" + name + ", position=" + position + "]";
91     }
92 }