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.common.Revision;
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.
51 * Revision of source, possibly not present
53 * semantic version of source
55 SemVerSourceIdentifier(final String name, final Optional<Revision> revision, final SemVer semVer) {
56 super(name, revision);
61 * Creates new YANG Schema semVer source identifier.
66 * semantic version of source
68 SemVerSourceIdentifier(final String name, final SemVer semVer) {
69 this(name, Optional.empty(), semVer);
73 * Returns semantic version of source if it was specified.
75 * @return revision of source.
77 public Optional<SemVer> getSemanticVersion() {
78 return Optional.ofNullable(semVer);
82 * Creates new YANG Schema semVer source identifier.
87 * semantic version of source
89 public static SemVerSourceIdentifier create(final String moduleName, final SemVer semVer) {
90 return new SemVerSourceIdentifier(moduleName, semVer);
94 * Creates new YANG Schema semVer source identifier.
99 * Revision of source in format YYYY-mm-dd
101 * semantic version of source
103 public static SemVerSourceIdentifier create(final String moduleName, final Revision revision,
104 final SemVer semVer) {
105 return new SemVerSourceIdentifier(moduleName, Optional.ofNullable(revision), semVer);
109 * Creates new YANG Schema semVer source identifier.
114 * Optional of source revision in format YYYY-mm-dd. If not
115 * present, default value will be used.
117 * semantic version of source
119 public static SemVerSourceIdentifier create(final String moduleName, final Optional<Revision> revision,
120 final SemVer semVer) {
121 return new SemVerSourceIdentifier(moduleName, revision, semVer);
125 public int hashCode() {
126 final int prime = 31;
128 result = prime * result + Objects.hashCode(getName());
129 result = prime * result + Objects.hashCode(semVer);
134 public boolean equals(final Object obj) {
138 if (!(obj instanceof SemVerSourceIdentifier)) {
141 final SemVerSourceIdentifier other = (SemVerSourceIdentifier) obj;
142 return Objects.equals(getName(), other.getName()) && Objects.equals(semVer, other.semVer);
146 public String toString() {
147 return "SemVerSourceIdentifier [name=" + getName() + "(" + semVer + ")" + "@" + getRevision() + "]";