BUG-4688: Make SourceIdentifier use Revision
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / SemVerSourceIdentifier.java
index 88f5168d7fa38448af94d7bfa6af45bd52ed3cfd..7e5e04ab0f8a947d93aefada34d9aac15f403b0a 100644 (file)
@@ -8,14 +8,15 @@
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.Optional;
 import java.util.Objects;
+import java.util.Optional;
 import org.opendaylight.yangtools.concepts.SemVer;
-import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.common.Revision;
 
 /**
- * YANG Schema source identifier with specified semantic version
+ * YANG Schema source identifier with specified semantic version.
  *
+ * <p>
  * Simple transfer object represents identifier of source for YANG schema
  * (module or submodule), which consists of
  * <ul>
@@ -24,9 +25,11 @@ import org.opendaylight.yangtools.yang.model.api.Module;
  * <li>(Optional) Module revision ({link {@link #getRevision()}
  * </ul>
  *
+ * <p>
  * Source identifier is designated to be carry only necessary information to
  * look-up YANG model source and to be used by various SchemaSourceProviders.
  *
+ * <p>
  * <b>Note:</b>On source retrieval layer it is impossible to distinguish between
  * YANG module and/or submodule unless source is present.
  *
@@ -44,14 +47,14 @@ public final class SemVerSourceIdentifier extends SourceIdentifier {
      *
      * @param name
      *            Name of schema
-     * @param formattedRevision
-     *            Optional of source revision in format YYYY-mm-dd. If not
-     *            present, default value will be used.
+     * @param revision
+     *            Revision of source, possibly not present
      * @param semVer
      *            semantic version of source
      */
-    SemVerSourceIdentifier(final String name, final Optional<String> formattedRevision, final SemVer semVer) {
-        this(name, formattedRevision.or(NOT_PRESENT_FORMATTED_REVISION), semVer);
+    SemVerSourceIdentifier(final String name, final Optional<Revision> revision, final SemVer semVer) {
+        super(name, revision);
+        this.semVer = semVer;
     }
 
     /**
@@ -63,34 +66,16 @@ public final class SemVerSourceIdentifier extends SourceIdentifier {
      *            semantic version of source
      */
     SemVerSourceIdentifier(final String name, final SemVer semVer) {
-        this(name, Optional.absent(), semVer);
+        this(name, Optional.empty(), semVer);
     }
 
     /**
-     * Creates new YANG Schema semVer source identifier.
+     * Returns semantic version of source if it was specified.
      *
-     * @param name
-     *            Name of schema
-     * @param formattedRevision
-     *            Revision of source in format YYYY-mm-dd
-     * @param semVer
-     *            semantic version of source
+     * @return revision of source.
      */
-    SemVerSourceIdentifier(final String name, final String formattedRevision, final SemVer semVer) {
-        super(name, formattedRevision);
-        this.semVer = semVer == null ? Module.DEFAULT_SEMANTIC_VERSION : semVer;
-    }
-
-    /**
-     * Returns semantic version of source or
-     * {@link Module#DEFAULT_SEMANTIC_VERSION} if semantic version was not
-     * supplied.
-     *
-     * @return revision of source or {@link Module#DEFAULT_SEMANTIC_VERSION} if
-     *         revision was not supplied.
-     */
-    public SemVer getSemanticVersion() {
-        return semVer;
+    public Optional<SemVer> getSemanticVersion() {
+        return Optional.ofNullable(semVer);
     }
 
     /**
@@ -115,9 +100,9 @@ public final class SemVerSourceIdentifier extends SourceIdentifier {
      * @param semVer
      *            semantic version of source
      */
-    public static SemVerSourceIdentifier create(final String moduleName, final String revision,
+    public static SemVerSourceIdentifier create(final String moduleName, final Revision revision,
             final SemVer semVer) {
-        return new SemVerSourceIdentifier(moduleName, revision, semVer);
+        return new SemVerSourceIdentifier(moduleName, Optional.ofNullable(revision), semVer);
     }
 
     /**
@@ -131,8 +116,8 @@ public final class SemVerSourceIdentifier extends SourceIdentifier {
      * @param semVer
      *            semantic version of source
      */
-    public static SemVerSourceIdentifier create(final String moduleName,
-            final Optional<String> revision, final SemVer semVer) {
+    public static SemVerSourceIdentifier create(final String moduleName, final Optional<Revision> revision,
+            final SemVer semVer) {
         return new SemVerSourceIdentifier(moduleName, revision, semVer);
     }