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.opendaylight.yangtools.concepts.SemVer;
14 import org.opendaylight.yangtools.yang.model.api.Module;
17 * YANG Schema source identifier with specified semantic version.
20 * Simple transfer object represents identifier of source for YANG schema
21 * (module or submodule), which consists of
23 * <li>YANG schema name {@link #getName()}
24 * <li>Semantic version of yang schema {@link #getSemanticVersion()}
25 * <li>(Optional) Module revision ({link {@link #getRevision()}
29 * Source identifier is designated to be carry only necessary information to
30 * look-up YANG model source and to be used by various 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 SemVerSourceIdentifier extends SourceIdentifier {
42 private static final long serialVersionUID = 1L;
43 private final SemVer semVer;
46 * Creates new YANG Schema semVer source identifier.
50 * @param formattedRevision
51 * Optional of source revision in format YYYY-mm-dd. If not
52 * present, default value will be used.
54 * semantic version of source
56 SemVerSourceIdentifier(final String name, final Optional<String> formattedRevision, final SemVer semVer) {
57 super(name, formattedRevision);
58 this.semVer = semVer == null ? Module.DEFAULT_SEMANTIC_VERSION : semVer;
62 * Creates new YANG Schema semVer source identifier.
67 * semantic version of source
69 SemVerSourceIdentifier(final String name, final SemVer semVer) {
70 this(name, Optional.empty(), semVer);
74 * Returns semantic version of source or
75 * {@link Module#DEFAULT_SEMANTIC_VERSION} if semantic version was not
78 * @return revision of source or {@link Module#DEFAULT_SEMANTIC_VERSION} if
79 * revision was not supplied.
81 public SemVer getSemanticVersion() {
86 * Creates new YANG Schema semVer source identifier.
91 * semantic version of source
93 public static SemVerSourceIdentifier create(final String moduleName, final SemVer semVer) {
94 return new SemVerSourceIdentifier(moduleName, semVer);
98 * Creates new YANG Schema semVer source identifier.
103 * Revision of source in format YYYY-mm-dd
105 * semantic version of source
107 public static SemVerSourceIdentifier create(final String moduleName, final String revision,
108 final SemVer semVer) {
109 return new SemVerSourceIdentifier(moduleName, Optional.of(revision), semVer);
113 * Creates new YANG Schema semVer source identifier.
118 * Optional of source revision in format YYYY-mm-dd. If not
119 * present, default value will be used.
121 * semantic version of source
123 public static SemVerSourceIdentifier create(final String moduleName,
124 final Optional<String> revision, final SemVer semVer) {
125 return new SemVerSourceIdentifier(moduleName, revision, semVer);
129 public int hashCode() {
130 final int prime = 31;
132 result = prime * result + Objects.hashCode(getName());
133 result = prime * result + Objects.hashCode(semVer);
138 public boolean equals(final Object obj) {
142 if (!(obj instanceof SemVerSourceIdentifier)) {
145 final SemVerSourceIdentifier other = (SemVerSourceIdentifier) obj;
146 return Objects.equals(getName(), other.getName()) && Objects.equals(semVer, other.semVer);
150 public String toString() {
151 return "SemVerSourceIdentifier [name=" + getName() + "(" + semVer + ")" + "@" + getRevision() + "]";