f93dee2a0ff1d6848fd77d16e1de1102408ea703
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / 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;
9
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableList;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Objects;
16 import org.opendaylight.yangtools.concepts.Immutable;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
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 public final class EnumPairImpl implements EnumPair, Immutable {
24     private final List<UnknownSchemaNode> unknownSchemaNodes;
25     private final String description;
26     private final String reference;
27     private final SchemaPath path;
28     private final Status status;
29     private final Integer value;
30     private final String name;
31
32     public EnumPairImpl(final String name, final Integer value, final SchemaPath path, final String description,
33             final String reference, final Status status, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
34         this.path = Preconditions.checkNotNull(path);
35         this.value = Preconditions.checkNotNull(value);
36         this.name = Preconditions.checkNotNull(name);
37         this.description = description;
38         this.reference = reference;
39         this.status = Preconditions.checkNotNull(status);
40         this.unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodes);
41     }
42
43     @Override
44     public QName getQName() {
45         return path.getLastComponent();
46     }
47
48     @Override
49     public SchemaPath getPath() {
50         return path;
51     }
52
53     @Override
54     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
55         return unknownSchemaNodes;
56     }
57
58     @Override
59     public String getDescription() {
60         return description;
61     }
62
63     @Override
64     public String getReference() {
65         return reference;
66     }
67
68     @Override
69     public Status getStatus() {
70         return status;
71     }
72
73     @Override
74     public String getName() {
75         return name;
76     }
77
78     @Override
79     public Integer getValue() {
80         return value;
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = 1;
87         result = prime * result + Objects.hashCode(path.getLastComponent());
88         result = prime * result + Objects.hashCode(path);
89         result = prime * result + Objects.hashCode(unknownSchemaNodes);
90         result = prime * result + Objects.hashCode(name);
91         result = prime * result + Objects.hashCode(value);
92         return result;
93     }
94
95     @Override
96     public boolean equals(final Object obj) {
97         if (this == obj) {
98             return true;
99         }
100         if (!(obj instanceof EnumPair)) {
101             return false;
102         }
103         EnumPair other = (EnumPair) obj;
104         if (!Objects.equals(name, other.getName())) {
105             return false;
106         }
107
108         return Objects.equals(value, other.getValue()) && Objects.equals(getPath(), other.getPath()) &&
109                 Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes());
110     }
111
112     @Override
113     public String toString() {
114         return MoreObjects.toStringHelper(this).add("name", name).add("value", value).toString();
115     }
116 }