2 * Copyright (c) 2014 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/eplv10.html
8 package org.opendaylight.yangtools.yang.model.util.repo;
10 import com.google.common.base.Optional;
12 public final class SourceIdentifier {
14 private final String name;
15 private final String revision;
17 public SourceIdentifier(String name, Optional<String> formattedRevision) {
20 this.revision = formattedRevision.orNull();
24 public int hashCode() {
27 result = prime * result + ((name == null) ? 0 : name.hashCode());
28 result = prime * result + ((revision == null) ? 0 : revision.hashCode());
33 public boolean equals(Object obj) {
38 if (getClass() != obj.getClass())
40 SourceIdentifier other = (SourceIdentifier) obj;
42 if (other.name != null)
44 } else if (!name.equals(other.name))
46 if (revision == null) {
47 if (other.revision != null)
49 } else if (!revision.equals(other.revision))
54 public String getName() {
58 public String getRevision() {
62 public static SourceIdentifier create(String moduleName, Optional<String> revision) {
63 return new SourceIdentifier(moduleName, revision);
66 public String toYangFilename() {
67 return toYangFileName(name, Optional.fromNullable(revision));
71 public String toString() {
72 return "SourceIdentifier [name=" + name + "@" + revision + "]";
75 public static final String toYangFileName(String moduleName, Optional<String> revision) {
76 StringBuilder filename = new StringBuilder(moduleName);
77 if (revision.isPresent()) {
79 filename.append(revision.get());
81 filename.append(".yang");
82 return filename.toString();