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 static com.google.common.base.Preconditions.checkNotNull;
13 import com.google.common.base.Optional;
15 import java.util.Date;
16 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
19 * ModuleIdentifier that can be used for indexing/searching by name.
20 * Name is only non-null attribute.
21 * Equality check on namespace and revision is only triggered if they are non-null
23 public class ModuleIdentifierImpl implements ModuleIdentifier {
24 private final String name;
25 private final Optional<URI> namespace;
26 private final Optional<Date> revision;
28 public ModuleIdentifierImpl(String name, Optional<URI> namespace, Optional<Date> revision) {
29 this.name = checkNotNull(name);
30 this.namespace = checkNotNull(namespace);
31 this.revision = checkNotNull(revision);
35 public Date getRevision() {
36 return revision.orNull();
40 public String getName() {
45 public URI getNamespace() {
46 return namespace.orNull();
50 public String toString() {
51 return "ModuleIdentifierImpl{" +
52 "name='" + name + '\'' +
53 ", namespace=" + namespace +
54 ", revision=" + revision +
59 public boolean equals(Object o) {
63 if (o == null || (o instanceof ModuleIdentifier == false)) {
67 ModuleIdentifier that = (ModuleIdentifier) o;
69 if (!name.equals(that.getName())) {
72 // only fail if this namespace is non-null
73 if (namespace.isPresent() && namespace.get().equals(that.getNamespace()) == false) {
76 // only fail if this revision is non-null
77 if (revision.isPresent() && revision.get().equals(that.getRevision()) == false) {
85 public int hashCode() {
86 return name.hashCode();