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 com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import java.util.Objects;
16 * YANG Schema revision source identifier
18 * Simple transfer object represents revision identifier of source for YANG
19 * schema (module or submodule), which consists of
21 * <li>YANG schema name ({@link #getName()}
22 * <li>Module revision (optional) ({link {@link #getRevision()})
25 * Revision source identifier is designated to be carry only necessary
26 * information to look-up YANG model source and to be used by various
27 * SchemaSourceProviders.
29 * <b>Note:</b>On source retrieval layer it is impossible to distinguish between
30 * YANG module and/or submodule unless source is present.
33 * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2
34 * and http://tools.ietf.org/html/rfc6022#section-3.1 ).
37 public final class RevisionSourceIdentifier extends SourceIdentifier {
38 private static final long serialVersionUID = 1L;
42 * Creates new YANG Schema revision source identifier for sources without
48 RevisionSourceIdentifier(final String name) {
53 * Creates new YANG Schema revision source identifier.
57 * @param formattedRevision
58 * Revision of source in format YYYY-mm-dd
60 RevisionSourceIdentifier(final String name, final String formattedRevision) {
61 super(Preconditions.checkNotNull(name), Preconditions.checkNotNull(formattedRevision));
66 * Creates new YANG Schema revision source identifier.
70 * @param formattedRevision
71 * Revision of source in format YYYY-mm-dd. If not present,
72 * default value will be used.
74 RevisionSourceIdentifier(final String name, final Optional<String> formattedRevision) {
75 super(name, formattedRevision);
80 * Creates new YANG Schema revision source identifier.
85 * Revision of source in format YYYY-mm-dd. If not present,
86 * default value will be used.
88 public static RevisionSourceIdentifier create(final String moduleName,
89 final Optional<String> revision) {
90 return new RevisionSourceIdentifier(moduleName, revision);
94 * Creates new YANG Schema revision source identifier.
99 * Revision of source in format YYYY-mm-dd
101 public static RevisionSourceIdentifier create(final String moduleName, final String revision) {
102 return new RevisionSourceIdentifier(moduleName, revision);
106 * Creates new YANG Schema revision source identifier for sources without
112 public static RevisionSourceIdentifier create(final String moduleName) {
113 return new RevisionSourceIdentifier(moduleName);
117 public int hashCode() {
118 final int prime = 31;
120 result = prime * result + Objects.hashCode(getName());
121 result = prime * result + Objects.hashCode(getRevision());
126 public boolean equals(final Object obj) {
130 if (!(obj instanceof RevisionSourceIdentifier)) {
133 final RevisionSourceIdentifier other = (RevisionSourceIdentifier) obj;
134 return Objects.equals(getName(), other.getName()) && Objects.equals(getRevision(), other.getRevision());
138 public String toString() {
139 final StringBuilder sb = new StringBuilder("RevisionSourceIdentifier [name=");
140 sb.append(getName());
142 final String rev = getRevision();
144 sb.append('@').append(rev);
146 return sb.append(']').toString();