Merge "BUG-1304: rework BindingGeneratorImpl from xtend to java"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / ModuleImpl.java
index bfeef7a43e5a9ffd63aad89776a18a88a2ffc35a..d2c3729871227954435671f78d27bece1e06a8f9 100644 (file)
@@ -2,7 +2,6 @@ package org.opendaylight.yangtools.yang.parser.builder.impl;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.net.URI;
@@ -12,6 +11,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
@@ -28,10 +28,9 @@ import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
 
 public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implements Module, Immutable {
 
-    private final URI namespace;
+    private final QNameModule qnameModule;
     private final String name;
     private final String sourcePath;
-    private final Optional<Date> revision;
     private final String prefix;
     private final String yangVersion;
     private final String organization;
@@ -61,11 +60,11 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
         super(builder);
         this.name = checkNotNull(name, "Missing name");
         this.sourcePath = sourcePath; //TODO: can this be nullable?
-        this.imports = ImmutableSet.copyOf(builder.imports);
-        this.namespace = builder.getNamespace();
+        this.imports = ImmutableSet.<ModuleImport> copyOf(builder.imports.values());
         this.prefix = builder.getPrefix();
-        this.revision = builder.getRevision() == null ? Optional.<Date>absent():
-                Optional.of(new Date(builder.getRevision().getTime()));
+
+        this.qnameModule = QNameModule.create(builder.getNamespace(),
+                builder.getRevision() == null ? null : new Date(builder.getRevision().getTime()));
         this.yangVersion = builder.getYangVersion();
         this.organization = builder.getOrganization();
         this.contact = builder.getContact();
@@ -88,7 +87,7 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
 
     @Override
     public URI getNamespace() {
-        return namespace;
+        return qnameModule.getNamespace();
     }
 
     @Override
@@ -98,11 +97,7 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
 
     @Override
     public Date getRevision() {
-        if (revision.isPresent()) {
-            return new Date(revision.get().getTime());
-        } else {
-            return null;
-        }
+        return qnameModule.getRevision();
     }
 
     @Override
@@ -170,6 +165,7 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
         return unknownNodes;
     }
 
+    @Override
     public String getSource() {
         return source;
     }
@@ -178,10 +174,9 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
         result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((revision == null) ? 0 : revision.hashCode());
         result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+        result = prime * result + qnameModule.hashCode();
         return result;
     }
 
@@ -197,13 +192,6 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
             return false;
         }
         ModuleImpl other = (ModuleImpl) obj;
-        if (namespace == null) {
-            if (other.namespace != null) {
-                return false;
-            }
-        } else if (!namespace.equals(other.namespace)) {
-            return false;
-        }
         if (name == null) {
             if (other.name != null) {
                 return false;
@@ -211,11 +199,7 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
         } else if (!name.equals(other.name)) {
             return false;
         }
-        if (revision == null) {
-            if (other.revision != null) {
-                return false;
-            }
-        } else if (!revision.equals(other.revision)) {
+        if (!qnameModule.equals(other.qnameModule)) {
             return false;
         }
         if (yangVersion == null) {
@@ -239,11 +223,16 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
         StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
         sb.append("[");
         sb.append("name=").append(name);
-        sb.append(", namespace=").append(namespace);
-        sb.append(", revision=").append(revision);
+        sb.append(", namespace=").append(getNamespace());
+        sb.append(", revision=").append(getRevision());
         sb.append(", prefix=").append(prefix);
         sb.append(", yangVersion=").append(yangVersion);
         sb.append("]");
         return sb.toString();
     }
-}
\ No newline at end of file
+
+    @Override
+    public QNameModule getQNameModule() {
+        return qnameModule;
+    }
+}