Use SimpleImmutableEntry in ValueWithQName 01/27501/1
authorRobert Varga <rovarga@cisco.com>
Sun, 27 Sep 2015 12:22:09 +0000 (14:22 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 27 Sep 2015 13:11:45 +0000 (15:11 +0200)
SimpleImmutableEntry gives us everything we need, there is no need for
duplicate (and incorrect from Entry interface definition) code.

Change-Id: I4490d9b5fc06547ee30fd05d31495a9a7005956e
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/ValueWithQName.java

index 289f9c35e10dd01db4e56df1323aa2d080042e1c..83298d83b1a0f7b6c0fba935234b3c553b3e2c68 100644 (file)
@@ -7,75 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.codec;
 
-import java.util.Map.Entry;
-import java.util.Objects;
+import java.util.AbstractMap.SimpleImmutableEntry;
 import org.opendaylight.yangtools.yang.common.QName;
 
-public class ValueWithQName<V> implements Entry<QName, V>{
-    final QName qname;
-    final V value;
+public class ValueWithQName<V> extends SimpleImmutableEntry<QName, V> {
+    private static final long serialVersionUID = 1L;
 
     public ValueWithQName(final QName qname, final V value) {
-        super();
-        this.qname = qname;
-        this.value = value;
+        super(qname, value);
     }
 
     public QName getQname() {
-        return qname;
-    }
-
-    @Override
-    public V getValue() {
-        return value;
-    }
-
-    @Override
-    public QName getKey() {
-        return qname;
-    }
-
-    @Override
-    public V setValue(final V value) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + Objects.hashCode(qname);
-        result = prime * result + Objects.hashCode(value);
-        return result;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        @SuppressWarnings("rawtypes")
-        ValueWithQName other = (ValueWithQName) obj;
-        if (qname == null) {
-            if (other.qname != null) {
-                return false;
-            }
-        } else if (!qname.equals(other.qname)) {
-            return false;
-        }
-        if (value == null) {
-            if (other.value != null) {
-                return false;
-            }
-        } else if (!value.equals(other.value)) {
-            return false;
-        }
-        return true;
+        return getKey();
     }
 }