BUG-6316: Fix Bit and EnumPair's position/value types
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / 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.util.type;
9
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Preconditions;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
18
19 final class EnumPairImpl implements EnumPair, Immutable {
20     private final List<UnknownSchemaNode> unknownSchemaNodes;
21     private final String description;
22     private final String reference;
23     private final Status status;
24     private final String name;
25     private final int value;
26
27     EnumPairImpl(final String name, final int value, final String description, final String reference,
28             final Status status, final List<UnknownSchemaNode> unknownSchemaNodes) {
29         this.name = Preconditions.checkNotNull(name);
30         this.value = value;
31         this.description = description;
32         this.reference = reference;
33         this.status = Preconditions.checkNotNull(status);
34         this.unknownSchemaNodes = Preconditions.checkNotNull(unknownSchemaNodes);
35     }
36
37     @Override
38     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
39         return unknownSchemaNodes;
40     }
41
42     @Override
43     public String getDescription() {
44         return description;
45     }
46
47     @Override
48     public String getReference() {
49         return reference;
50     }
51
52     @Override
53     public Status getStatus() {
54         return status;
55     }
56
57     @Override
58     public String getName() {
59         return name;
60     }
61
62     @Override
63     public int getValue() {
64         return value;
65     }
66
67     @Override
68     public int hashCode() {
69         final int prime = 31;
70         int result = 1;
71         result = prime * result + unknownSchemaNodes.hashCode();
72         result = prime * result + name.hashCode();
73         result = prime * result + Integer.hashCode(value);
74         return result;
75     }
76
77     @Override
78     public boolean equals(final Object obj) {
79         if (this == obj) {
80             return true;
81         }
82         if (!(obj instanceof EnumPair)) {
83             return false;
84         }
85         EnumPair other = (EnumPair) obj;
86         if (!Objects.equals(name, other.getName())) {
87             return false;
88         }
89
90         return value == other.getValue() && Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes());
91     }
92
93     @Override
94     public String toString() {
95         return MoreObjects.toStringHelper(this).add("name", name).add("value", value).toString();
96     }
97 }