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 static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.util.Objects;
14 import java.util.Optional;
17 * YANG Schema revision source identifier.
20 * Simple transfer object represents revision identifier of source for YANG
21 * schema (module or submodule), which consists of
23 * <li>YANG schema name ({@link #getName()}
24 * <li>Module revision (optional) ({link {@link #getRevision()})
28 * Revision source identifier is designated to be carry only necessary
29 * information to look-up YANG model source and to be used by various
30 * SchemaSourceProviders.
33 * <b>Note:</b>On source retrieval layer it is impossible to distinguish between
34 * YANG module and/or submodule unless source is present.
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
51 RevisionSourceIdentifier(final String name) {
56 * Creates new YANG Schema revision source identifier.
60 * @param formattedRevision
61 * Revision of source in format YYYY-mm-dd
63 RevisionSourceIdentifier(final String name, final String formattedRevision) {
64 super(requireNonNull(name), requireNonNull(formattedRevision));
68 * Creates new YANG Schema revision source identifier.
72 * @param formattedRevision
73 * Revision of source in format YYYY-mm-dd. If not present,
74 * default value will be used.
76 RevisionSourceIdentifier(final String name, final Optional<String> formattedRevision) {
77 super(name, formattedRevision);
81 * Creates new YANG Schema revision source identifier.
86 * Revision of source in format YYYY-mm-dd. If not present,
87 * default value will be used.
89 public static RevisionSourceIdentifier create(final String moduleName,
90 final Optional<String> revision) {
91 return new RevisionSourceIdentifier(moduleName, revision);
95 * Creates new YANG Schema revision source identifier.
100 * Revision of source in format YYYY-mm-dd
102 public static RevisionSourceIdentifier create(final String moduleName, final String revision) {
103 return new RevisionSourceIdentifier(moduleName, revision);
107 * Creates new YANG Schema revision source identifier for sources without
113 public static RevisionSourceIdentifier create(final String moduleName) {
114 return new RevisionSourceIdentifier(moduleName);
118 public int hashCode() {
119 final int prime = 31;
121 result = prime * result + Objects.hashCode(getName());
122 result = prime * result + Objects.hashCode(getRevision());
127 public boolean equals(final Object obj) {
131 if (!(obj instanceof RevisionSourceIdentifier)) {
134 final RevisionSourceIdentifier other = (RevisionSourceIdentifier) obj;
135 return Objects.equals(getName(), other.getName()) && Objects.equals(getRevision(), other.getRevision());
139 public String toString() {
140 final StringBuilder sb = new StringBuilder("RevisionSourceIdentifier [name=");
141 sb.append(getName());
143 final String rev = getRevision();
145 sb.append('@').append(rev);
147 return sb.append(']').toString();