2 * Copyright (c) 2016 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.repo.api;
10 import com.google.common.annotations.Beta;
11 import java.util.Objects;
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.Revision;
18 * YANG Schema revision source identifier.
21 * Simple transfer object represents revision identifier of source for YANG schema (module or submodule), which consists
24 * <li>YANG schema name ({@link #getName()}
25 * <li>Module revision (optional) ({link {@link #getRevision()})
29 * Revision source identifier is designated to be carry only necessary information to look-up YANG model source
30 * and to be used by various SchemaSourceProviders.
33 * <b>Note:</b>On source retrieval layer it is impossible to distinguish between YANG module and/or submodule unless
37 * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2
38 * and http://tools.ietf.org/html/rfc6022#section-3.1 ).
41 public final class RevisionSourceIdentifier extends SourceIdentifier {
42 private static final long serialVersionUID = 1L;
45 * Creates new YANG Schema revision source identifier for sources without a revision.
47 * @param name Name of schema
49 RevisionSourceIdentifier(final String name) {
54 * Creates new YANG Schema revision source identifier.
56 * @param name Name of schema
57 * @param revision Revision of source, may be null
59 RevisionSourceIdentifier(final String name, final @Nullable Revision revision) {
60 super(name, revision);
64 * Creates new YANG Schema revision source identifier.
66 * @param name Name of schema
67 * @param formattedRevision Revision of source, potentially not present
69 private RevisionSourceIdentifier(final String name, final Optional<Revision> revision) {
70 super(name, revision);
74 * Creates new YANG Schema revision source identifier.
76 * @param moduleName Name of schema
77 * @param revision Revision of source in format YYYY-mm-dd. If not present, default value will be used.
79 public static @NonNull RevisionSourceIdentifier create(final String moduleName, final Optional<Revision> revision) {
80 return new RevisionSourceIdentifier(moduleName, revision);
84 * Creates new YANG Schema revision source identifier.
86 * @param moduleName Name of schema
87 * @param revision Revision of source, may be null
89 public static @NonNull RevisionSourceIdentifier create(final String moduleName, final @Nullable Revision revision) {
90 return new RevisionSourceIdentifier(moduleName, revision);
94 * Creates new YANG Schema revision source identifier for sources without
100 public static @NonNull RevisionSourceIdentifier create(final String moduleName) {
101 return new RevisionSourceIdentifier(moduleName);
105 public int hashCode() {
106 final int prime = 31;
108 result = prime * result + Objects.hashCode(getName());
109 result = prime * result + Objects.hashCode(getRevision());
114 public boolean equals(final Object obj) {
118 if (!(obj instanceof RevisionSourceIdentifier)) {
121 final RevisionSourceIdentifier other = (RevisionSourceIdentifier) obj;
122 return Objects.equals(getName(), other.getName()) && Objects.equals(getRevision(), other.getRevision());
126 public String toString() {
127 final StringBuilder sb = new StringBuilder("RevisionSourceIdentifier [name=");
128 sb.append(getName());
130 final Optional<Revision> rev = getRevision();
131 if (rev.isPresent()) {
132 sb.append('@').append(rev.get());
134 return sb.append(']').toString();