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;
11 import com.google.common.base.Optional;
13 import java.util.Date;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
18 * ModuleIdentifier that can be used for indexing/searching by name.
19 * Name is only non-null attribute.
20 * Equality check on namespace and revision is only triggered if they are non-null
22 public class ModuleIdentifierImpl implements ModuleIdentifier {
23 private final QNameModule qnameModule;
24 private final String name;
26 public ModuleIdentifierImpl(final String name, final Optional<URI> namespace, final Optional<Date> revision) {
27 this.name = checkNotNull(name);
28 this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull());
32 public QNameModule getQNameModule() {
37 public Date getRevision() {
38 return qnameModule.getRevision();
42 public String getName() {
47 public URI getNamespace() {
48 return qnameModule.getNamespace();
52 public String toString() {
53 return "ModuleIdentifierImpl{" +
54 "name='" + name + '\'' +
55 ", namespace=" + getNamespace() +
56 ", revision=" + qnameModule.getFormattedRevision() +
61 public boolean equals(final Object o) {
65 if (!(o instanceof ModuleIdentifier)) {
69 ModuleIdentifier that = (ModuleIdentifier) o;
71 if (!name.equals(that.getName())) {
75 // only fail if this namespace is non-null
76 if (getNamespace() != null && !getNamespace().equals(that.getNamespace())) {
79 // only fail if this revision is non-null
80 if (getRevision() != null && !getRevision().equals(that.getRevision())) {
88 public int hashCode() {
89 return name.hashCode();