Use Objects.hashCode()
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BitImpl.java
1 /*
2  * Copyright (c) 2013 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.util;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
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.BitsTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
21
22 public final class BitImpl implements BitsTypeDefinition.Bit, Immutable {
23     private final Long position;
24     private final QName qname;
25     private final SchemaPath schemaPath;
26     private final String description;
27     private final String reference;
28     private final Status status;
29     private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
30
31     public BitImpl(final Long position, final QName qname, final SchemaPath schemaPath, final String description,
32             final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
33         this.position = Preconditions.checkNotNull(position, "Position should not be null");
34         this.qname = Preconditions.checkNotNull(qname, "QName should not be null");
35         this.schemaPath = Preconditions.checkNotNull(schemaPath, "Schema Path should not be null");
36         this.description = description;
37         this.reference = reference;
38         this.status = status;
39         if (unknownNodes != null) {
40             this.unknownNodes = unknownNodes;
41         }
42     }
43
44     @Override
45     public QName getQName() {
46         return qname;
47     }
48
49     @Override
50     public SchemaPath getPath() {
51         return schemaPath;
52     }
53
54     @Override
55     public String getDescription() {
56         return description;
57     }
58
59     @Override
60     public String getReference() {
61         return reference;
62     }
63
64     @Override
65     public Status getStatus() {
66         return status;
67     }
68
69     @Override
70     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
71         return unknownNodes;
72     }
73
74     @Override
75     public Long getPosition() {
76         return position;
77     }
78
79     @Override
80     public String getName() {
81         return qname.getLocalName();
82     }
83
84     @Override
85     public int hashCode() {
86         final int prime = 31;
87         int result = 1;
88         result = prime * result + qname.hashCode();
89         result = prime * result + schemaPath.hashCode();
90         result = prime * result + position.hashCode();
91         result = prime * result + Objects.hashCode(unknownNodes);
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 == null) {
101             return false;
102         }
103         if (getClass() != obj.getClass()) {
104             return false;
105         }
106         Bit other = (Bit) obj;
107         if (qname == null) {
108             if (other.getQName() != null) {
109                 return false;
110             }
111         } else if (!qname.equals(other.getQName())) {
112             return false;
113         }
114         if (schemaPath == null) {
115             if (other.getPath() != null) {
116                 return false;
117             }
118         } else if (!schemaPath.equals(other.getPath())) {
119             return false;
120         }
121         return true;
122     }
123
124     @Override
125     public String toString() {
126         return Bit.class.getSimpleName() + "[name=" + qname.getLocalName() + ", position=" + position + "]";
127     }
128
129 }