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.common;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
17 * Enumeration of supported YANG versions.
19 public enum YangVersion {
21 * Version 1, as defined in RFC6020.
23 VERSION_1("1", "RFC6020"),
25 * Version 1.1, as defined in RFC7950.
27 VERSION_1_1("1.1", "RFC7950");
29 private final @NonNull String str;
30 private final @NonNull String reference;
32 YangVersion(final @NonNull String str, final @NonNull String reference) {
33 this.str = requireNonNull(str);
34 this.reference = requireNonNull(reference);
38 * Parse a YANG version from its textual representation.
40 * @param str String to parse
41 * @return YANG version, or {@code null}
42 * @throws NullPointerException if the string is {@code null}
44 public static @Nullable YangVersion forString(final @NonNull String str) {
45 return switch (requireNonNull(str)) {
46 case "1" -> VERSION_1;
47 case "1.1" -> VERSION_1_1;
53 * Parse a YANG version from its textual representation.
55 * @param str String to parse
56 * @return YANG version
57 * @throws NullPointerException if the string is {@code null}
58 * @throws IllegalArgumentException if the string is not recognized
60 public static @NonNull YangVersion ofString(final @NonNull String str) {
61 final var ret = forString(str);
65 throw new IllegalArgumentException("Invalid YANG version " + str);
69 * Parse a YANG version from its textual representation.
71 * @param str String to parse
72 * @return An Optional YANG version
73 * @throws NullPointerException if the string is {@code null}
74 * @deprecated Use {@link #forString(String)} or {@link #ofString(String)}
76 @Deprecated(since = "11.0.0", forRemoval = true)
77 public static Optional<YangVersion> parse(final @NonNull String str) {
78 return Optional.ofNullable(forString(str));
82 * Return the normative reference defining this YANG version.
84 * @return Normative reference.
86 public @NonNull String reference() {
91 * Return the normative reference defining this YANG version.
93 * @return Normative reference.
94 * @deprecated Use {@link #reference()} instead
96 @Deprecated(since = "11.0.0", forRemoval = true)
97 public @NonNull String getReference() {
102 public @NonNull String toString() {