BUG-865: integrate SchemaAwareNormalizedNodeStreamWriter
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / SourceIdentifier.java
index 44a8cceee7609533e079e4aa4c64fa318469918e..fba3630573038bbcc8d3c789e7c0b030372e3704 100644 (file)
@@ -3,18 +3,20 @@
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-
+import java.util.Objects;
+import java.util.regex.Pattern;
 import org.opendaylight.yangtools.concepts.Identifier;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.objcache.ObjectCache;
 import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 
 /**
  * YANG Schema source identifier
@@ -27,8 +29,7 @@ import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
  * </ul>
  *
  * Source identifier is designated to be carry only necessary information
- * to look-up YANG model source and to be used by {@link AdvancedSchemaSourceProvider}
- * and similar.
+ * to look-up YANG model source and to be used by various SchemaSourceProviders.
  *
  * <b>Note:</b>On source retrieval layer it is impossible to distinguish
  * between YANG module and/or submodule unless source is present.
@@ -45,11 +46,33 @@ public final class SourceIdentifier implements Identifier, Immutable {
      */
     public static final String NOT_PRESENT_FORMATTED_REVISION = "0000-00-00";
 
+    /**
+     *
+     * Simplified compiled revision pattern in format YYYY-mm-dd, which checks
+     * only distribution of number elements.
+     * <p>
+     * For checking if supplied string is real date, use {@link SimpleDateFormatUtil}
+     * instead.
+     *
+     */
+    public static final Pattern REVISION_PATTERN = Pattern.compile("\\d\\d\\d\\d-\\d\\d-\\d\\d");
+
     private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(SourceIdentifier.class);
     private static final long serialVersionUID = 1L;
     private final String revision;
     private final String name;
 
+    /**
+     *
+     * Creates new YANG Schema source identifier for sources without revision.
+     * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision.
+     *
+     * @param name Name of schema
+     */
+    public SourceIdentifier(final String name) {
+        this(name, NOT_PRESENT_FORMATTED_REVISION);
+    }
+
     /**
      * Creates new YANG Schema source identifier.
      *
@@ -81,17 +104,6 @@ public final class SourceIdentifier implements Identifier, Immutable {
         return CACHE.getReference(this);
     }
 
-    /**
-     *
-     * Creates new YANG Schema source identifier for sources without revision.
-     * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision.
-     *
-     * @param name Name of schema
-     */
-    public SourceIdentifier(final String name) {
-        this(name, NOT_PRESENT_FORMATTED_REVISION);
-    }
-
     /**
      * Returns model name
      *
@@ -114,8 +126,8 @@ public final class SourceIdentifier implements Identifier, Immutable {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+        result = prime * result + Objects.hashCode(name);
+        result = prime * result + Objects.hashCode(revision);
         return result;
     }
 
@@ -131,21 +143,7 @@ public final class SourceIdentifier implements Identifier, Immutable {
             return false;
         }
         SourceIdentifier other = (SourceIdentifier) obj;
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (revision == null) {
-            if (other.revision != null) {
-                return false;
-            }
-        } else if (!revision.equals(other.revision)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(name, other.name) && Objects.equals(revision, other.revision);
     }
 
     public static SourceIdentifier create(final String moduleName, final Optional<String> revision) {
@@ -161,7 +159,7 @@ public final class SourceIdentifier implements Identifier, Immutable {
      * Where revision is  date in format YYYY-mm-dd.
      * <p>
      *
-     * @see http://tools.ietf.org/html/rfc6020#section-5.2
+     * @see <a href="http://tools.ietf.org/html/rfc6020#section-5.2">RFC6020</a>
      *
      * @return Filename for this source identifier.
      */
@@ -188,7 +186,7 @@ public final class SourceIdentifier implements Identifier, Immutable {
      *
      * @return Filename for this source identifier.
      */
-    public static final String toYangFileName(final String moduleName, final Optional<String> revision) {
+    public static String toYangFileName(final String moduleName, final Optional<String> revision) {
         StringBuilder filename = new StringBuilder(moduleName);
         if (revision.isPresent()) {
             filename.append('@');