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
9 package org.opendaylight.yangtools.yang.parser.builder.impl;
11 import com.google.common.base.Optional;
12 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
15 import java.util.Date;
17 import static com.google.common.base.Preconditions.checkNotNull;
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 public class ModuleIdentifierImpl implements ModuleIdentifier {
25 private final String name;
26 private final Optional<URI> namespace;
27 private final Optional<Date> revision;
29 public ModuleIdentifierImpl(String name, Optional<URI> namespace, Optional<Date> revision) {
30 this.name = checkNotNull(name);
31 this.namespace = checkNotNull(namespace);
32 this.revision = checkNotNull(revision);
36 public Date getRevision() {
37 return revision.orNull();
41 public String getName() {
46 public URI getNamespace() {
47 return namespace.orNull();
51 public String toString() {
52 return "ModuleIdentifierImpl{" +
53 "name='" + name + '\'' +
54 ", namespace=" + namespace +
55 ", revision=" + revision +
60 public boolean equals(Object o) {
64 if (o == null || (o instanceof ModuleIdentifier == false)) {
68 ModuleIdentifier that = (ModuleIdentifier) o;
70 if (!name.equals(that.getName())) {
73 // only fail if this namespace is non-null
74 if (namespace.isPresent() && namespace.get().equals(that.getNamespace()) == false) {
77 // only fail if this revision is non-null
78 if (revision.isPresent() && revision.get().equals(that.getRevision()) == false) {
86 public int hashCode() {
87 return name.hashCode();