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;
13 import java.util.Optional;
14 import org.opendaylight.yangtools.yang.common.Revision;
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 * @deprecated This class will be removed with {@link ModuleIdentifier}
26 public final class ModuleIdentifierImpl implements ModuleIdentifier {
27 private final Revision revision;
28 private final String name;
30 private ModuleIdentifierImpl(final String name, final Optional<Revision> revision) {
31 this.name = checkNotNull(name);
32 this.revision = revision.orElse(null);
35 public static ModuleIdentifier create(final String name, final Optional<Revision> revision) {
36 return new ModuleIdentifierImpl(name, revision);
40 public Optional<Revision> getRevision() {
41 return Optional.ofNullable(revision);
45 public String getName() {
50 public String toString() {
51 return "ModuleIdentifierImpl{"
52 + "name='" + name + '\''
53 + ", revision=" + revision
58 public boolean equals(final Object obj) {
62 if (!(obj instanceof ModuleIdentifier)) {
66 ModuleIdentifier other = (ModuleIdentifier) obj;
68 if (!name.equals(other.getName())) {
72 // only fail if this revision is non-null
73 if (getRevision() != null && !getRevision().equals(other.getRevision())) {
81 public int hashCode() {
82 return name.hashCode();