Cleanup DocumentedNode
[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 java.util.Optional;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.yangtools.concepts.Immutable;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
20
21 final class EnumPairImpl implements EnumPair, Immutable {
22     private final List<UnknownSchemaNode> unknownSchemaNodes;
23     private final String description;
24     private final String reference;
25     private final Status status;
26     private final String name;
27     private final int value;
28
29     EnumPairImpl(final String name, final int value, final String description, final String reference,
30             final Status status, final List<UnknownSchemaNode> unknownSchemaNodes) {
31         this.name = Preconditions.checkNotNull(name);
32         this.value = value;
33         this.description = description;
34         this.reference = reference;
35         this.status = Preconditions.checkNotNull(status);
36         this.unknownSchemaNodes = Preconditions.checkNotNull(unknownSchemaNodes);
37     }
38
39     @Nonnull
40     @Override
41     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
42         return unknownSchemaNodes;
43     }
44
45     @Override
46     public Optional<String> getDescription() {
47         return Optional.ofNullable(description);
48     }
49
50     @Override
51     public Optional<String> getReference() {
52         return Optional.ofNullable(reference);
53     }
54
55     @Nonnull
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 }