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 static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.util.Objects;
14 import java.util.Optional;
15 import javax.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.common.Revision;
19 * YANG Schema revision source identifier.
22 * Simple transfer object represents revision identifier of source for YANG
23 * schema (module or submodule), which consists of
25 * <li>YANG schema name ({@link #getName()}
26 * <li>Module revision (optional) ({link {@link #getRevision()})
30 * Revision source identifier is designated to be carry only necessary
31 * information to look-up YANG model source and to be used by various
32 * SchemaSourceProviders.
35 * <b>Note:</b>On source retrieval layer it is impossible to distinguish between
36 * YANG module and/or submodule unless source is present.
39 * (For further reference see: http://tools.ietf.org/html/rfc6020#section-5.2
40 * and http://tools.ietf.org/html/rfc6022#section-3.1 ).
43 public final class RevisionSourceIdentifier extends SourceIdentifier {
44 private static final long serialVersionUID = 1L;
47 * Creates new YANG Schema revision source identifier for sources without
53 RevisionSourceIdentifier(final String name) {
58 * Creates new YANG Schema revision source identifier.
63 * Revision of source, may be null
65 RevisionSourceIdentifier(final String name, @Nullable final Revision revision) {
66 super(requireNonNull(name), revision);
70 * Creates new YANG Schema revision source identifier.
74 * @param formattedRevision
75 * Revision of source, potentially not present
77 private RevisionSourceIdentifier(final String name, final Optional<Revision> revision) {
78 super(name, revision);
82 * Creates new YANG Schema revision source identifier.
87 * Revision of source in format YYYY-mm-dd. If not present,
88 * default value will be used.
90 public static RevisionSourceIdentifier create(final String moduleName, final Optional<Revision> revision) {
91 return new RevisionSourceIdentifier(moduleName, revision);
95 * Creates new YANG Schema revision source identifier.
100 * Revision of source, may be null
102 public static RevisionSourceIdentifier create(final String moduleName, @Nullable final Revision revision) {
103 return new RevisionSourceIdentifier(moduleName, revision);
107 * Creates new YANG Schema revision source identifier for sources without
113 public static RevisionSourceIdentifier create(final String moduleName) {
114 return new RevisionSourceIdentifier(moduleName);
118 public int hashCode() {
119 final int prime = 31;
121 result = prime * result + Objects.hashCode(getName());
122 result = prime * result + Objects.hashCode(getRevision());
127 public boolean equals(final Object obj) {
131 if (!(obj instanceof RevisionSourceIdentifier)) {
134 final RevisionSourceIdentifier other = (RevisionSourceIdentifier) obj;
135 return Objects.equals(getName(), other.getName()) && Objects.equals(getRevision(), other.getRevision());
139 public String toString() {
140 final StringBuilder sb = new StringBuilder("RevisionSourceIdentifier [name=");
141 sb.append(getName());
143 final Optional<Revision> rev = getRevision();
144 if (rev.isPresent()) {
145 sb.append('@').append(rev.get());
147 return sb.append(']').toString();