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 java.util.Objects;
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
19 * Simple transfer object represents identifier of source for YANG schema
20 * (module or submodule), which consists of
22 * <li>YANG schema name {@link #getName()}
23 * <li>Semantic version of yang schema {@link #getSemanticVersion()}
24 * <li>(Optional) Module revision ({link {@link #getRevision()}
27 * Source identifier is designated to be carry only necessary information to
28 * look-up YANG model source and to be used by various SchemaSourceProviders.
30 * <b>Note:</b>On source retrieval layer it is impossible to distinguish between
31 * YANG module and/or submodule unless source is present.
34 * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2
35 * and http://tools.ietf.org/html/rfc6022#section-3.1 ).
38 public final class SemVerSourceIdentifier extends SourceIdentifier {
39 private static final long serialVersionUID = 1L;
40 private final SemVer semVer;
43 * Creates new YANG Schema semVer source identifier.
47 * @param formattedRevision
48 * Optional of source revision in format YYYY-mm-dd. If not
49 * present, default value will be used.
51 * semantic version of source
53 SemVerSourceIdentifier(final String name, final Optional<String> formattedRevision, final SemVer semVer) {
54 super(name, formattedRevision);
55 this.semVer = semVer == null ? Module.DEFAULT_SEMANTIC_VERSION : semVer;
59 * Creates new YANG Schema semVer source identifier.
64 * semantic version of source
66 SemVerSourceIdentifier(final String name, final SemVer semVer) {
67 this(name, Optional.absent(), semVer);
71 * Returns semantic version of source or
72 * {@link Module#DEFAULT_SEMANTIC_VERSION} if semantic version was not
75 * @return revision of source or {@link Module#DEFAULT_SEMANTIC_VERSION} if
76 * revision was not supplied.
78 public SemVer getSemanticVersion() {
83 * Creates new YANG Schema semVer source identifier.
88 * semantic version of source
90 public static SemVerSourceIdentifier create(final String moduleName, final SemVer semVer) {
91 return new SemVerSourceIdentifier(moduleName, semVer);
95 * Creates new YANG Schema semVer source identifier.
100 * Revision of source in format YYYY-mm-dd
102 * semantic version of source
104 public static SemVerSourceIdentifier create(final String moduleName, final String revision,
105 final SemVer semVer) {
106 return new SemVerSourceIdentifier(moduleName, Optional.of(revision), semVer);
110 * Creates new YANG Schema semVer source identifier.
115 * Optional of source revision in format YYYY-mm-dd. If not
116 * present, default value will be used.
118 * semantic version of source
120 public static SemVerSourceIdentifier create(final String moduleName,
121 final Optional<String> revision, final SemVer semVer) {
122 return new SemVerSourceIdentifier(moduleName, revision, semVer);
126 public int hashCode() {
127 final int prime = 31;
129 result = prime * result + Objects.hashCode(getName());
130 result = prime * result + Objects.hashCode(semVer);
135 public boolean equals(final Object obj) {
139 if (!(obj instanceof SemVerSourceIdentifier)) {
142 final SemVerSourceIdentifier other = (SemVerSourceIdentifier) obj;
143 return Objects.equals(getName(), other.getName()) && Objects.equals(semVer, other.semVer);
147 public String toString() {
148 return "SemVerSourceIdentifier [name=" + getName() + "(" + semVer + ")" + "@" + getRevision() + "]";