X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Frepo%2Fapi%2FSourceIdentifier.java;h=48ce2a7c0b2c4aa950214af5644e2e3b0da44244;hb=e403e34bcb508c48aa606a1cd81a386fb73c5db6;hp=f46ed3f426553be6f37a5a94e72b7d96b965c24c;hpb=c55eefb2dcc799601c6ed51409cd5f670fb7fe73;p=yangtools.git diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SourceIdentifier.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SourceIdentifier.java index f46ed3f426..48ce2a7c0b 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SourceIdentifier.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SourceIdentifier.java @@ -10,6 +10,8 @@ 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 com.google.common.collect.Interner; +import com.google.common.collect.Interners; import java.util.regex.Pattern; import org.opendaylight.yangtools.concepts.Identifier; import org.opendaylight.yangtools.concepts.Immutable; @@ -18,30 +20,19 @@ import org.opendaylight.yangtools.objcache.ObjectCacheFactory; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; /** - * YANG Schema source identifier + * Base class of YANG Schema source identifiers. * - * Simple transfer object represents identifier of source for YANG schema (module or submodule), - * which consists of - * + * Source identifiers are designated to be carry only necessary information to + * look-up YANG model source and to be used by various SchemaSourceProviders. * - * Source identifier is designated to be carry only necessary information - * to look-up YANG model source and to be used by various SchemaSourceProviders. - * - * Note:On source retrieval layer it is impossible to distinguish - * between YANG module and/or submodule unless source is present. - * - *

- * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2 and - * http://tools.ietf.org/html/rfc6022#section-3.1 ). + * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2 + * and http://tools.ietf.org/html/rfc6022#section-3.1 ). */ @Beta -public final class SourceIdentifier implements Identifier, Immutable { +public abstract class SourceIdentifier implements Identifier, Immutable { /** - * Default revision for sources without specified revision. - * Marks the source as oldest. + * Default revision for sources without specified revision. Marks the source + * as oldest. */ public static final String NOT_PRESENT_FORMATTED_REVISION = "0000-00-00"; @@ -50,25 +41,41 @@ public final class SourceIdentifier implements Identifier, Immutable { * Simplified compiled revision pattern in format YYYY-mm-dd, which checks * only distribution of number elements. *

- * For checking if supplied string is real date, use {@link SimpleDateFormatUtil} - * instead. + * 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 Interner INTERNER = Interners.newWeakInterner(); + 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 + */ + SourceIdentifier(final String name) { + this(name, NOT_PRESENT_FORMATTED_REVISION); + } + /** * Creates new YANG Schema source identifier. * - * @param name Name of schema - * @param formattedRevision Revision of source in format YYYY-mm-dd + * @param name + * Name of schema + * @param formattedRevision + * Revision of source in format YYYY-mm-dd */ - public SourceIdentifier(final String name, final String formattedRevision) { + SourceIdentifier(final String name, final String formattedRevision) { this.name = Preconditions.checkNotNull(name); this.revision = Preconditions.checkNotNull(formattedRevision); } @@ -77,10 +84,13 @@ public final class SourceIdentifier implements Identifier, Immutable { * * Creates new YANG Schema source identifier. * - * @param name Name of schema - * @param formattedRevision Revision of source in format YYYY-mm-dd. If not present, default value will be used. + * @param name + * Name of schema + * @param formattedRevision + * Revision of source in format YYYY-mm-dd. If not present, + * default value will be used. */ - public SourceIdentifier(final String name, final Optional formattedRevision) { + SourceIdentifier(final String name, final Optional formattedRevision) { this(name, formattedRevision.or(NOT_PRESENT_FORMATTED_REVISION)); } @@ -89,19 +99,18 @@ public final class SourceIdentifier implements Identifier, Immutable { * * @return A potentially shared reference, not guaranteed to be unique. */ + @Deprecated public SourceIdentifier cachedReference() { return CACHE.getReference(this); } /** + * Return an interned reference to a equivalent SemVerSourceIdentifier. * - * Creates new YANG Schema source identifier for sources without revision. - * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision. - * - * @param name Name of schema + * @return Interned reference, or this object if it was interned. */ - public SourceIdentifier(final String name) { - this(name, NOT_PRESENT_FORMATTED_REVISION); + public SourceIdentifier intern() { + return INTERNER.intern(this); } /** @@ -122,55 +131,17 @@ public final class SourceIdentifier implements Identifier, Immutable { return revision; } - @Override - 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()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - 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; - } - + @Deprecated public static SourceIdentifier create(final String moduleName, final Optional revision) { - return new SourceIdentifier(moduleName, revision); + return new RevisionSourceIdentifier(moduleName, revision); } /** * Returns filename for this YANG module as specified in RFC 6020. * - * Returns filename in format - * name ['@' revision] '.yang' + * Returns filename in format name ['@' revision] '.yang' *

- * Where revision is date in format YYYY-mm-dd. + * Where revision is date in format YYYY-mm-dd. *

* * @see RFC6020 @@ -181,26 +152,19 @@ public final class SourceIdentifier implements Identifier, Immutable { return toYangFileName(name, Optional.fromNullable(revision)); } - @Override - public String toString() { - return "SourceIdentifier [name=" + name + "@" + revision + "]"; - } - /** * Returns filename for this YANG module as specified in RFC 6020. * - * Returns filename in format - * moduleName ['@' revision] '.yang' + * Returns filename in format moduleName ['@' revision] '.yang' * * Where Where revision-date is in format YYYY-mm-dd. * *

- * See - * http://tools.ietf.org/html/rfc6020#section-5.2 + * See http://tools.ietf.org/html/rfc6020#section-5.2 * * @return Filename for this source identifier. */ - public static final String toYangFileName(final String moduleName, final Optional revision) { + public static String toYangFileName(final String moduleName, final Optional revision) { StringBuilder filename = new StringBuilder(moduleName); if (revision.isPresent()) { filename.append('@'); @@ -209,5 +173,4 @@ public final class SourceIdentifier implements Identifier, Immutable { filename.append(".yang"); return filename.toString(); } - }