Bug 4662: Introduce a SemanticVersion concept - import processing
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / ModuleImportImpl.java
index 376511663e411b8a66114dacc1bae68661ba191f..f6ec3488bba2a47dfc1d1e4b6172a3e01665b139 100644 (file)
@@ -7,19 +7,28 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import com.google.common.base.Preconditions;
 import java.util.Date;
 import java.util.Objects;
+import org.opendaylight.yangtools.concepts.SemVer;
+import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 
 public final class ModuleImportImpl implements ModuleImport {
     private final String moduleName;
     private final Date revision;
+    private final SemVer semVer;
     private final String prefix;
 
     public ModuleImportImpl(final String moduleName, final Date revision, final String prefix) {
-        this.moduleName = moduleName;
+        this(moduleName, revision, prefix, Module.DEFAULT_SEMANTIC_VERSION);
+    }
+
+    public ModuleImportImpl(final String moduleName, final Date revision, final String prefix, final SemVer semVer) {
+        this.moduleName = Preconditions.checkNotNull(moduleName, "Module name must not be null.");
         this.revision = revision;
-        this.prefix = prefix;
+        this.prefix = Preconditions.checkNotNull(prefix, "Import prefix must not be null.");
+        this.semVer = Preconditions.checkNotNull(semVer, "Semantic version of module must not be null.");
     }
 
     @Override
@@ -32,6 +41,11 @@ public final class ModuleImportImpl implements ModuleImport {
         return revision;
     }
 
+    @Override
+    public SemVer getSemanticVersion() {
+        return semVer;
+    }
+
     @Override
     public String getPrefix() {
         return prefix;
@@ -44,6 +58,7 @@ public final class ModuleImportImpl implements ModuleImport {
         result = prime * result + Objects.hashCode(moduleName);
         result = prime * result + Objects.hashCode(revision);
         result = prime * result + Objects.hashCode(prefix);
+        result = prime * result + Objects.hashCode(semVer);
         return result;
     }
 
@@ -68,6 +83,9 @@ public final class ModuleImportImpl implements ModuleImport {
         if (!Objects.equals(getPrefix(), other.getPrefix())) {
             return false;
         }
+        if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) {
+            return false;
+        }
         return true;
     }