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.
78 * @return A RevisionSourceIdentifier
80 public static @NonNull RevisionSourceIdentifier create(final String moduleName, final Optional<Revision> revision) {
81 return new RevisionSourceIdentifier(moduleName, revision);
85 * Creates new YANG Schema revision source identifier.
87 * @param moduleName Name of schema
88 * @param revision Revision of source, may be null
89 * @return A RevisionSourceIdentifier
91 public static @NonNull RevisionSourceIdentifier create(final String moduleName, final @Nullable Revision revision) {
92 return new RevisionSourceIdentifier(moduleName, revision);
96 * Creates new YANG Schema revision source identifier for sources without
99 * @param moduleName Name of schema
100 * @return A RevisionSourceIdentifier
102 public static @NonNull RevisionSourceIdentifier create(final String moduleName) {
103 return new RevisionSourceIdentifier(moduleName);
107 public int hashCode() {
108 final int prime = 31;
110 result = prime * result + Objects.hashCode(getName());
111 result = prime * result + Objects.hashCode(getRevision());
116 public boolean equals(final Object obj) {
120 if (!(obj instanceof RevisionSourceIdentifier)) {
123 final RevisionSourceIdentifier other = (RevisionSourceIdentifier) obj;
124 return Objects.equals(getName(), other.getName()) && Objects.equals(getRevision(), other.getRevision());
128 public String toString() {
129 final StringBuilder sb = new StringBuilder("RevisionSourceIdentifier [name=");
130 sb.append(getName());
132 final Optional<Revision> rev = getRevision();
133 if (rev.isPresent()) {
134 sb.append('@').append(rev.get());
136 return sb.append(']').toString();