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
43 * revision. {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as
49 RevisionSourceIdentifier(final String name) {
50 this(name, NOT_PRESENT_FORMATTED_REVISION);
54 * Creates new YANG Schema revision source identifier.
58 * @param formattedRevision
59 * Revision of source in format YYYY-mm-dd
61 RevisionSourceIdentifier(final String name, final String formattedRevision) {
62 super(Preconditions.checkNotNull(name), Preconditions.checkNotNull(formattedRevision));
67 * Creates new YANG Schema revision source identifier.
71 * @param formattedRevision
72 * Revision of source in format YYYY-mm-dd. If not present,
73 * default value will be used.
75 RevisionSourceIdentifier(final String name, final Optional<String> formattedRevision) {
76 this(name, formattedRevision.or(NOT_PRESENT_FORMATTED_REVISION));
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);
108 * Creates new YANG Schema revision source identifier for sources without
109 * revision. {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as
115 public static RevisionSourceIdentifier create(final String moduleName) {
116 return new RevisionSourceIdentifier(moduleName);
120 public int hashCode() {
121 final int prime = 31;
123 result = prime * result + Objects.hashCode(getName());
124 result = prime * result + Objects.hashCode(getRevision());
129 public boolean equals(final Object obj) {
133 if (!(obj instanceof RevisionSourceIdentifier)) {
136 final RevisionSourceIdentifier other = (RevisionSourceIdentifier) obj;
137 return Objects.equals(getName(), other.getName()) && Objects.equals(getRevision(), other.getRevision());
141 public String toString() {
142 return "RevisionSourceIdentifier [name=" + getName() + "@" + getRevision() + "]";