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 public final class SemVerSourceIdentifier extends SourceIdentifier {
43 private static final long serialVersionUID = 1L;
44 private final SemVer semVer;
47 * Creates new YANG Schema semVer source identifier.
49 * @param name Name of schema
50 * @param revision Revision of source, possibly not present
51 * @param semVer semantic version of source
53 SemVerSourceIdentifier(final String name, final Optional<Revision> revision, final @Nullable SemVer semVer) {
54 super(name, revision);
59 * Creates new YANG Schema semVer source identifier.
61 * @param name Name of schema
62 * @param semVer semantic version of source
64 SemVerSourceIdentifier(final String name, final @Nullable SemVer semVer) {
65 this(name, Optional.empty(), semVer);
69 * Returns semantic version of source if it was specified.
71 * @return revision of source.
73 public Optional<SemVer> getSemanticVersion() {
74 return Optional.ofNullable(semVer);
78 * Creates new YANG Schema semVer source identifier.
80 * @param moduleName Name of schema
81 * @param semVer semantic version of source
82 * @return A SemVerSourceIdentifier
84 public static @NonNull SemVerSourceIdentifier create(final String moduleName, final SemVer semVer) {
85 return new SemVerSourceIdentifier(moduleName, semVer);
89 * Creates new YANG Schema semVer source identifier.
91 * @param moduleName Name of schema
92 * @param revision Revision of source in format YYYY-mm-dd
93 * @param semVer semantic version of source
94 * @return A SemVerSourceIdentifier
96 public static @NonNull SemVerSourceIdentifier create(final String moduleName, final Revision revision,
97 final SemVer semVer) {
98 return new SemVerSourceIdentifier(moduleName, Optional.ofNullable(revision), semVer);
102 * Creates new YANG Schema semVer source identifier.
104 * @param moduleName Name of schema
105 * @param revision Optional of source revision in format YYYY-mm-dd. If not present, default value will be used.
106 * @param semVer semantic version of source
107 * @return A SemVerSourceIdentifier
109 public static @NonNull SemVerSourceIdentifier create(final String moduleName, final Optional<Revision> revision,
110 final SemVer semVer) {
111 return new SemVerSourceIdentifier(moduleName, revision, semVer);
115 public int hashCode() {
116 final int prime = 31;
118 result = prime * result + Objects.hashCode(getName());
119 result = prime * result + Objects.hashCode(semVer);
124 public boolean equals(final Object obj) {
128 if (!(obj instanceof SemVerSourceIdentifier)) {
131 final SemVerSourceIdentifier other = (SemVerSourceIdentifier) obj;
132 return Objects.equals(getName(), other.getName()) && Objects.equals(semVer, other.semVer);
136 public String toString() {
137 return "SemVerSourceIdentifier [name=" + getName() + "(" + semVer + ")" + "@" + getRevision() + "]";