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;
15 import java.util.Date;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
21 * ModuleIdentifier that can be used for indexing/searching by name.
22 * Name is only non-null attribute.
23 * Equality check on namespace and revision is only triggered if they are non-null
25 public class ModuleIdentifierImpl implements ModuleIdentifier {
26 private final QNameModule qnameModule;
27 private final String name;
29 public ModuleIdentifierImpl(final String name, final Optional<URI> namespace, final Optional<Date> revision) {
30 this.name = checkNotNull(name);
31 this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull());
35 public QNameModule getQNameModule() {
40 public Date getRevision() {
41 return qnameModule.getRevision();
45 public String getName() {
50 public URI getNamespace() {
51 return qnameModule.getNamespace();
55 public String toString() {
56 return "ModuleIdentifierImpl{" +
57 "name='" + name + '\'' +
58 ", namespace=" + getNamespace() +
59 ", revision=" + getRevision() +
64 public boolean equals(final Object o) {
68 if (o == null || (o instanceof ModuleIdentifier == false)) {
72 ModuleIdentifier that = (ModuleIdentifier) o;
74 if (!name.equals(that.getName())) {
78 // only fail if this namespace is non-null
79 if (getNamespace() != null && !getNamespace().equals(that.getNamespace())) {
82 // only fail if this revision is non-null
83 if (getRevision() != null && !getRevision().equals(that.getRevision())) {
91 public int hashCode() {
92 return name.hashCode();