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.model.util;
10 import static com.google.common.base.Preconditions.checkNotNull;
12 import com.google.common.annotations.Beta;
14 import java.util.Date;
15 import java.util.Optional;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
20 * ModuleIdentifier that can be used for indexing/searching by name.
21 * Name is only non-null attribute.
22 * Equality check on namespace and revision is only triggered if they are non-null
24 * @deprecated This class will be removed with {@link ModuleIdentifier}
28 public final class ModuleIdentifierImpl implements ModuleIdentifier {
29 private final QNameModule qnameModule;
30 private final String name;
32 private ModuleIdentifierImpl(final String name, final Optional<URI> namespace, final Optional<Date> revision) {
33 this.name = checkNotNull(name);
34 this.qnameModule = QNameModule.create(namespace.orElse(null), revision.orElse(null));
37 public static ModuleIdentifier create(final String name, final Optional<Date> revision) {
38 return new ModuleIdentifierImpl(name, Optional.empty(), revision);
41 public static ModuleIdentifier create(final String name, final Optional<URI> namespace,
42 final Optional<Date> revision) {
43 return new ModuleIdentifierImpl(name, namespace, revision);
47 public Optional<Date> getRevision() {
48 return Optional.ofNullable(qnameModule.getRevision());
52 public String getName() {
57 public String toString() {
58 return "ModuleIdentifierImpl{"
59 + "name='" + name + '\''
60 + ", revision=" + qnameModule.getFormattedRevision()
65 public boolean equals(final Object obj) {
69 if (!(obj instanceof ModuleIdentifier)) {
73 ModuleIdentifier other = (ModuleIdentifier) obj;
75 if (!name.equals(other.getName())) {
79 // only fail if this revision is non-null
80 if (getRevision() != null && !getRevision().equals(other.getRevision())) {
88 public int hashCode() {
89 return name.hashCode();