Merge "Added methods for benchmarking of commit/write ops"
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / YangInstanceIdentifier.java
index e9f940a4555bad2af63797018916240a4209d3a3..84ebdf0f2035f30446e0098220050a80e9e7399d 100644 (file)
@@ -356,6 +356,7 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
     private static abstract class AbstractPathArgument implements PathArgument {
         private static final long serialVersionUID = -4546547994250849340L;
         private final QName nodeType;
+        private volatile transient Integer hash = null;
 
         protected AbstractPathArgument(final QName nodeType) {
             this.nodeType = Preconditions.checkNotNull(nodeType);
@@ -371,11 +372,26 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
             return nodeType.compareTo(o.getNodeType());
         }
 
-        @Override
-        public int hashCode() {
+        protected int hashCodeImpl() {
             return 31 + getNodeType().hashCode();
         }
 
+        @Override
+        public final int hashCode() {
+            Integer ret = hash;
+            if (ret == null) {
+                synchronized (this) {
+                    ret = hash;
+                    if (ret == null) {
+                        ret = hashCodeImpl();
+                        hash = ret;
+                    }
+                }
+            }
+
+            return ret;
+        }
+
         @Override
         public boolean equals(final Object obj) {
             if (this == obj) {
@@ -485,9 +501,9 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
         }
 
         @Override
-        public int hashCode() {
+        protected int hashCodeImpl() {
             final int prime = 31;
-            int result = super.hashCode();
+            int result = super.hashCodeImpl();
             result = prime * result;
 
             for (Entry<QName, Object> entry : keyValues.entrySet()) {
@@ -548,9 +564,9 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
         }
 
         @Override
-        public int hashCode() {
+        protected int hashCodeImpl() {
             final int prime = 31;
-            int result = super.hashCode();
+            int result = super.hashCodeImpl();
             result = prime * result + ((value == null) ? 0 : YangInstanceIdentifier.hashCode(value));
             return result;
         }