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.concepts.SemVer;
16 import org.opendaylight.yangtools.yang.common.Revision;
19 * YANG Schema source identifier with specified semantic version.
22 * Simple transfer object represents identifier of source for YANG schema (module or submodule), which consists of
24 * <li>YANG schema name {@link #getName()}
25 * <li>Semantic version of yang schema {@link #getSemanticVersion()}
26 * <li>(Optional) Module revision ({link {@link #getRevision()}
30 * Source identifier is designated to be carry only necessary information to look-up YANG model source and to be used
31 * by various SchemaSourceProviders.
34 * <b>Note:</b>On source retrieval layer it is impossible to distinguish between YANG module and/or submodule unless
38 * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2
39 * and http://tools.ietf.org/html/rfc6022#section-3.1 ).
42 @Deprecated(since = "7.0.11", forRemoval = true)
43 public final class SemVerSourceIdentifier extends SourceIdentifier {
44 private static final long serialVersionUID = 1L;
45 private final SemVer semVer;
48 * Creates new YANG Schema semVer source identifier.
50 * @param name Name of schema
51 * @param revision Revision of source, possibly not present
52 * @param semVer semantic version of source
54 SemVerSourceIdentifier(final String name, final Optional<Revision> revision, final @Nullable SemVer semVer) {
55 super(name, revision);
60 * Creates new YANG Schema semVer source identifier.
62 * @param name Name of schema
63 * @param semVer semantic version of source
65 SemVerSourceIdentifier(final String name, final @Nullable SemVer semVer) {
66 this(name, Optional.empty(), semVer);
70 * Returns semantic version of source if it was specified.
72 * @return revision of source.
74 public Optional<SemVer> getSemanticVersion() {
75 return Optional.ofNullable(semVer);
79 * Creates new YANG Schema semVer source identifier.
81 * @param moduleName Name of schema
82 * @param semVer semantic version of source
83 * @return A SemVerSourceIdentifier
85 public static @NonNull SemVerSourceIdentifier create(final String moduleName, final SemVer semVer) {
86 return new SemVerSourceIdentifier(moduleName, semVer);
90 * Creates new YANG Schema semVer source identifier.
92 * @param moduleName Name of schema
93 * @param revision Revision of source in format YYYY-mm-dd
94 * @param semVer semantic version of source
95 * @return A SemVerSourceIdentifier
97 public static @NonNull SemVerSourceIdentifier create(final String moduleName, final Revision revision,
98 final SemVer semVer) {
99 return new SemVerSourceIdentifier(moduleName, Optional.ofNullable(revision), semVer);
103 * Creates new YANG Schema semVer source identifier.
105 * @param moduleName Name of schema
106 * @param revision Optional of source revision in format YYYY-mm-dd. If not present, default value will be used.
107 * @param semVer semantic version of source
108 * @return A SemVerSourceIdentifier
110 public static @NonNull SemVerSourceIdentifier create(final String moduleName, final Optional<Revision> revision,
111 final SemVer semVer) {
112 return new SemVerSourceIdentifier(moduleName, revision, semVer);
116 public int hashCode() {
117 final int prime = 31;
119 result = prime * result + Objects.hashCode(getName());
120 result = prime * result + Objects.hashCode(semVer);
125 public boolean equals(final Object obj) {
129 if (!(obj instanceof SemVerSourceIdentifier)) {
132 final SemVerSourceIdentifier other = (SemVerSourceIdentifier) obj;
133 return Objects.equals(getName(), other.getName()) && Objects.equals(semVer, other.semVer);
137 public String toString() {
138 return "SemVerSourceIdentifier [name=" + getName() + "(" + semVer + ")" + "@" + getRevision() + "]";