Bug 2366 - new parser API - implementation of declared statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / ModuleIdentifierImpl.java
index 7a2c8f1c1d203e198a9df02079ae81aa03b1f10c..6e825dd666473fe878c46deb8bbc85f41c732517 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.yangtools.yang.parser.builder.impl;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
-import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 
+import com.google.common.base.Optional;
 import java.net.URI;
 import java.util.Date;
-
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 
@@ -65,7 +65,7 @@ public class ModuleIdentifierImpl implements ModuleIdentifier {
         if (this == o) {
             return true;
         }
-        if (o == null || (o instanceof ModuleIdentifier == false)) {
+        if (o == null || (!(o instanceof ModuleIdentifier))) {
             return false;
         }
 
@@ -79,8 +79,29 @@ public class ModuleIdentifierImpl implements ModuleIdentifier {
         if (getNamespace() != null && !getNamespace().equals(that.getNamespace())) {
             return false;
         }
+
+        Date defaultRev = SimpleDateFormatUtil.DEFAULT_DATE_REV;
+        Date defaultImp = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
+
+        // if revision is in import only, spec says that it is undefined which
+        // revision to take
+        if (getRevision() == defaultImp ^ that.getRevision() == defaultImp) {
+            return true;
+        }
+
+        // default and none revisions taken as equal
+        if ((defaultRev.equals(getRevision()) && that.getRevision() == null)
+                || (defaultRev.equals(that.getRevision()) && getRevision() == null)) {
+            return true;
+        }
+
+        // else if none of them is default and one null
+        if (getRevision() == null ^ that.getRevision() == null) {
+            return false;
+        }
+
         // only fail if this revision is non-null
-        if (getRevision() != null && !getRevision().equals(that.getRevision())) {
+        if (getRevision() != null && that.getRevision() != null && !getRevision().equals(that.getRevision())) {
             return false;
         }