Populate data/ hierarchy
[yangtools.git] / model / yang-model-ri / src / main / java / org / opendaylight / yangtools / yang / model / ri / type / EnumPairImpl.java
1 /*
2  * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.base.MoreObjects;
13 import com.google.common.collect.ImmutableList;
14 import java.util.Collection;
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.model.api.Status;
20 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
22
23 final class EnumPairImpl implements EnumPair, Immutable {
24     private final @NonNull ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
25     private final String description;
26     private final String reference;
27     private final @NonNull Status status;
28     private final @NonNull String name;
29     private final int value;
30
31     EnumPairImpl(final String name, final int value, final String description, final String reference,
32             final Status status, final ImmutableList<UnknownSchemaNode> unknownSchemaNodes) {
33         this.name = requireNonNull(name);
34         this.value = value;
35         this.description = description;
36         this.reference = reference;
37         this.status = requireNonNull(status);
38         this.unknownSchemaNodes = requireNonNull(unknownSchemaNodes);
39     }
40
41     @Override
42     public Collection<? extends UnknownSchemaNode> getUnknownSchemaNodes() {
43         return unknownSchemaNodes;
44     }
45
46     @Override
47     public Optional<String> getDescription() {
48         return Optional.ofNullable(description);
49     }
50
51     @Override
52     public Optional<String> getReference() {
53         return Optional.ofNullable(reference);
54     }
55
56     @Override
57     public Status getStatus() {
58         return status;
59     }
60
61     @Override
62     public String getName() {
63         return name;
64     }
65
66     @Override
67     public int getValue() {
68         return value;
69     }
70
71     @Override
72     public int hashCode() {
73         final int prime = 31;
74         int result = 1;
75         result = prime * result + unknownSchemaNodes.hashCode();
76         result = prime * result + name.hashCode();
77         result = prime * result + Integer.hashCode(value);
78         return result;
79     }
80
81     @Override
82     public boolean equals(final Object obj) {
83         if (this == obj) {
84             return true;
85         }
86         if (!(obj instanceof EnumPair)) {
87             return false;
88         }
89         EnumPair other = (EnumPair) obj;
90         if (!Objects.equals(name, other.getName())) {
91             return false;
92         }
93
94         return value == other.getValue() && Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes());
95     }
96
97     @Override
98     public String toString() {
99         return MoreObjects.toStringHelper(this).add("name", name).add("value", value).toString();
100     }
101 }