2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.builder.impl;
10 import static com.google.common.base.Preconditions.checkNotNull;
12 import com.google.common.base.Optional;
14 import java.util.Date;
15 import java.util.Objects;
16 import org.opendaylight.yangtools.concepts.SemVer;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
22 * ModuleIdentifier that can be used for indexing/searching by name.
23 * Name is only non-null attribute.
24 * Equality check on namespace and revision is only triggered if they are non-null
28 // FIXME: This class is used widely by yang statement parser. This class should be moved to one of yang statement
29 // parser packages after removal of deprecated pre-beryllium implementation.
30 public class ModuleIdentifierImpl implements ModuleIdentifier {
31 private final QNameModule qnameModule;
32 private final String name;
33 private final SemVer semVer;
35 public ModuleIdentifierImpl(final String name, final Optional<URI> namespace, final Optional<Date> revision) {
36 this(name, namespace, revision, Module.DEFAULT_SEMANTIC_VERSION);
39 public ModuleIdentifierImpl(final String name, final Optional<URI> namespace, final Optional<Date> revision, final SemVer semVer) {
40 this.name = checkNotNull(name);
41 this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull());
42 this.semVer = (semVer == null ? Module.DEFAULT_SEMANTIC_VERSION : semVer);
46 public QNameModule getQNameModule() {
51 public Date getRevision() {
52 return qnameModule.getRevision();
56 public SemVer getSemanticVersion() {
61 public String getName() {
66 public URI getNamespace() {
67 return qnameModule.getNamespace();
71 public String toString() {
72 return "ModuleIdentifierImpl{" +
73 "name='" + name + '\'' +
74 ", namespace=" + getNamespace() +
75 ", revision=" + qnameModule.getFormattedRevision() +
76 ", semantic version=" + semVer +
81 public boolean equals(final Object o) {
85 if (!(o instanceof ModuleIdentifier)) {
89 ModuleIdentifier other = (ModuleIdentifier) o;
91 if (!name.equals(other.getName())) {
95 // only fail if this namespace is non-null
96 if (getNamespace() != null && !getNamespace().equals(other.getNamespace())) {
99 // only fail if this revision is non-null
100 if (getRevision() != null && !getRevision().equals(other.getRevision())) {
104 if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) {
112 public int hashCode() {
113 return name.hashCode();