X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fbuilder%2Fimpl%2FModuleIdentifierImpl.java;h=dd42fec14e3e4f0c4fcd1bc4506edfbd4ae67a16;hb=4968d735af48cd6b0ea91b37fbd238316c7cb46c;hp=d94923dcd8dedd535fde929cfe556b475941e6fe;hpb=93e8c16d8deff8cd2935d09c445d2d7082503cb4;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java index d94923dcd8..dd42fec14e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.yangtools.yang.parser.builder.impl; import static com.google.common.base.Preconditions.checkNotNull; @@ -13,27 +12,49 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import java.net.URI; import java.util.Date; +import java.util.Objects; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; /** * ModuleIdentifier that can be used for indexing/searching by name. * Name is only non-null attribute. * Equality check on namespace and revision is only triggered if they are non-null + * */ + +// FIXME: This class is used widely by yang statement parser. This class should be moved to one of yang statement +// parser packages after removal of deprecated pre-beryllium implementation. public class ModuleIdentifierImpl implements ModuleIdentifier { + private final QNameModule qnameModule; private final String name; - private final Optional namespace; - private final Optional revision; + private final SemVer semVer; + + public ModuleIdentifierImpl(final String name, final Optional namespace, final Optional revision) { + this(name, namespace, revision, Module.DEFAULT_SEMANTIC_VERSION); + } - public ModuleIdentifierImpl(String name, Optional namespace, Optional revision) { + public ModuleIdentifierImpl(final String name, final Optional namespace, final Optional revision, final SemVer semVer) { this.name = checkNotNull(name); - this.namespace = checkNotNull(namespace); - this.revision = checkNotNull(revision); + this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull()); + this.semVer = (semVer == null ? Module.DEFAULT_SEMANTIC_VERSION : semVer); + } + + @Override + public QNameModule getQNameModule() { + return qnameModule; } @Override public Date getRevision() { - return revision.orNull(); + return qnameModule.getRevision(); + } + + @Override + public SemVer getSemanticVersion() { + return semVer; } @Override @@ -43,38 +64,44 @@ public class ModuleIdentifierImpl implements ModuleIdentifier { @Override public URI getNamespace() { - return namespace.orNull(); + return qnameModule.getNamespace(); } @Override public String toString() { return "ModuleIdentifierImpl{" + "name='" + name + '\'' + - ", namespace=" + namespace + - ", revision=" + revision + + ", namespace=" + getNamespace() + + ", revision=" + qnameModule.getFormattedRevision() + + ", semantic version=" + semVer + '}'; } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } - if (o == null || (o instanceof ModuleIdentifier == false)) { + if (!(o instanceof ModuleIdentifier)) { return false; } - ModuleIdentifier that = (ModuleIdentifier) o; + ModuleIdentifier other = (ModuleIdentifier) o; - if (!name.equals(that.getName())) { + if (!name.equals(other.getName())) { return false; } + // only fail if this namespace is non-null - if (namespace.isPresent() && namespace.get().equals(that.getNamespace()) == false) { + if (getNamespace() != null && !getNamespace().equals(other.getNamespace())) { return false; } // only fail if this revision is non-null - if (revision.isPresent() && revision.get().equals(that.getRevision()) == false) { + if (getRevision() != null && !getRevision().equals(other.getRevision())) { + return false; + } + + if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) { return false; }