Use Objects.hashCode()
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / ValueWithQName.java
1 /*
2  * Copyright (c) 2014 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.data.impl.codec;
9
10 import java.util.Map.Entry;
11 import java.util.Objects;
12 import org.opendaylight.yangtools.yang.common.QName;
13
14 public class ValueWithQName<V> implements Entry<QName, V>{
15     final QName qname;
16     final V value;
17
18     public ValueWithQName(final QName qname, final V value) {
19         super();
20         this.qname = qname;
21         this.value = value;
22     }
23
24     public QName getQname() {
25         return qname;
26     }
27
28     @Override
29     public V getValue() {
30         return value;
31     }
32
33     @Override
34     public QName getKey() {
35         return qname;
36     }
37
38     @Override
39     public V setValue(final V value) {
40         throw new UnsupportedOperationException();
41     }
42
43     @Override
44     public int hashCode() {
45         final int prime = 31;
46         int result = 1;
47         result = prime * result + Objects.hashCode(qname);
48         result = prime * result + Objects.hashCode(value);
49         return result;
50     }
51
52     @Override
53     public boolean equals(final Object obj) {
54         if (this == obj) {
55             return true;
56         }
57         if (obj == null) {
58             return false;
59         }
60         if (getClass() != obj.getClass()) {
61             return false;
62         }
63         @SuppressWarnings("rawtypes")
64         ValueWithQName other = (ValueWithQName) obj;
65         if (qname == null) {
66             if (other.qname != null) {
67                 return false;
68             }
69         } else if (!qname.equals(other.qname)) {
70             return false;
71         }
72         if (value == null) {
73             if (other.value != null) {
74                 return false;
75             }
76         } else if (!value.equals(other.value)) {
77             return false;
78         }
79         return true;
80     }
81 }