Do not instantiate new maps in LeafRefContextBuilder
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / leafref / LeafRefPath.java
index 649d911ac3ea88dd79e8fc010bf3da4fb74a7f7e..ff8aa82a23f8c46e0d4d709b6bf538e230277a18 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.leafref;
 
-import org.opendaylight.yangtools.concepts.Immutable;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.util.Arrays;
 import java.util.Iterator;
-import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 public abstract class LeafRefPath implements Immutable {
 
@@ -106,25 +106,11 @@ public abstract class LeafRefPath implements Immutable {
         return ret;
     }
 
-    /**
-     * Returns the complete path to schema node.
-     *
-     * @return list of <code>QNameWithPredicate</code> instances which
-     *         represents complete path to schema node
-     *
-     * @deprecated Use {@link #getPathFromRoot()} instead.
-     */
-    @Deprecated
-    public List<QNameWithPredicate> getPath() {
-        return getLegacyPath();
-    }
-
-    protected LeafRefPath(final LeafRefPath parent,
-            final QNameWithPredicate qname) {
+    protected LeafRefPath(final LeafRefPath parent, final QNameWithPredicate qname) {
         this.parent = parent;
         this.qname = qname;
 
-        int h = parent == null ? 0 : parent.hashCode();
+        int h = Objects.hashCode(parent);
         if (qname != null) {
             h = h * 31 + qname.hashCode();
         }
@@ -328,21 +314,7 @@ public abstract class LeafRefPath implements Immutable {
             return false;
         }
         final LeafRefPath other = (LeafRefPath) obj;
-
-        if (qname != null) {
-            if (!qname.equals(other.qname)) {
-                return false;
-            }
-        } else {
-            if (other.qname != null) {
-                return false;
-            }
-        }
-
-        if (parent == null) {
-            return other.parent == null;
-        }
-        return parent.equals(other.parent);
+        return Objects.equals(qname, other.qname) && Objects.equals(parent, other.parent);
     }
 
     @Override
@@ -354,7 +326,7 @@ public abstract class LeafRefPath implements Immutable {
         sb.append(isAbsolute() ? "Absolute path:" : "Relative path:");
 
         for (QNameWithPredicate qName : pathFromRoot) {
-            sb.append("/" + qName);
+            sb.append('/').append(qName);
         }
 
         return sb.toString();