Merge "Removed unused dependency."
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / AnyXmlEffectiveStatementImpl.java
index 85a5e63d3e4c30b37cd02f436689336efbab79f8..b2f469cb1bb4384d8ea62a5df9bbd003dedeb859 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.Collection;
 import java.util.LinkedList;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
@@ -44,6 +46,25 @@ public class AnyXmlEffectiveStatementImpl extends
         this.path = Utils.getSchemaPath(ctx);
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
@@ -110,32 +131,58 @@ public class AnyXmlEffectiveStatementImpl extends
         return result;
     }
 
+    private boolean checkQname(AnyXmlEffectiveStatementImpl other) {
+      if (qname == null) {
+        if (other.qname != null) {
+          return false;
+        }
+      } else if (!qname.equals(other.qname)) {
+        return false;
+      }
+      return true;
+    }
+
+    private boolean checkPath(AnyXmlEffectiveStatementImpl other) {
+      if (path == null) {
+        if (other.path != null) {
+            return false;
+        }
+      } else if (!path.equals(other.path)) {
+        return false;
+      }
+      return true;
+    }
+
+    private boolean checkObject(final Object obj) {
+      if (obj == null) {
+        return false;
+      }
+      if (getClass() != obj.getClass()) {
+        return false;
+      }
+      return true;
+    }
+
     @Override
     public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
+
+        if (!checkObject(obj)) {
+          return false;
         }
+
         AnyXmlEffectiveStatementImpl other = (AnyXmlEffectiveStatementImpl) obj;
-        if (qname == null) {
-            if (other.qname != null) {
-                return false;
-            }
-        } else if (!qname.equals(other.qname)) {
+
+        if (!checkQname(other)) {
             return false;
         }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
+
+        if (!checkPath(other)) {
             return false;
         }
+
         return true;
     }
 
@@ -150,4 +197,4 @@ public class AnyXmlEffectiveStatementImpl extends
         return sb.toString();
     }
 
-}
\ No newline at end of file
+}