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=6e825dd666473fe878c46deb8bbc85f41c732517;hb=481a692d463636bbcf75f023da71703913e1b605;hp=02f6abb780eca50e122c739bd6eb7e10e20ce9bd;hpb=8a22fe9a9294bf02c4c2829a547dfae02b434aea;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 02f6abb780..6e825dd666 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,16 +5,17 @@ * 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 com.google.common.base.Optional; -import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import com.google.common.base.Optional; import java.net.URI; import java.util.Date; - -import static com.google.common.base.Preconditions.checkNotNull; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; /** * ModuleIdentifier that can be used for indexing/searching by name. @@ -22,19 +23,22 @@ import static com.google.common.base.Preconditions.checkNotNull; * Equality check on namespace and revision is only triggered if they are non-null */ public class ModuleIdentifierImpl implements ModuleIdentifier { + private final QNameModule qnameModule; private final String name; - private final Optional namespace; - private final Optional revision; - public ModuleIdentifierImpl(String name, Optional namespace, Optional revision) { + public ModuleIdentifierImpl(final String name, final Optional namespace, final Optional revision) { this.name = checkNotNull(name); - this.namespace = checkNotNull(namespace); - this.revision = checkNotNull(revision); + this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull()); + } + + @Override + public QNameModule getQNameModule() { + return qnameModule; } @Override public Date getRevision() { - return revision.orNull(); + return qnameModule.getRevision(); } @Override @@ -44,24 +48,24 @@ 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=" + getRevision() + '}'; } @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 == null || (!(o instanceof ModuleIdentifier))) { return false; } @@ -70,12 +74,34 @@ public class ModuleIdentifierImpl implements ModuleIdentifier { if (!name.equals(that.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(that.getNamespace())) { + return false; + } + + Date defaultRev = SimpleDateFormatUtil.DEFAULT_DATE_REV; + Date defaultImp = SimpleDateFormatUtil.DEFAULT_DATE_IMP; + + // if revision is in import only, spec says that it is undefined which + // revision to take + if (getRevision() == defaultImp ^ that.getRevision() == defaultImp) { + return true; + } + + // default and none revisions taken as equal + if ((defaultRev.equals(getRevision()) && that.getRevision() == null) + || (defaultRev.equals(that.getRevision()) && getRevision() == null)) { + return true; + } + + // else if none of them is default and one null + if (getRevision() == null ^ that.getRevision() == null) { return false; } + // only fail if this revision is non-null - if (revision.isPresent() && revision.get().equals(that.getRevision()) == false) { + if (getRevision() != null && that.getRevision() != null && !getRevision().equals(that.getRevision())) { return false; }