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 com.google.common.annotations.Beta;
13 import com.google.common.collect.Maps;
14 import java.util.Arrays;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
20 * Enumeration of supported YANG versions.
22 * @author Robert Varga
25 public enum YangVersion {
27 * Version 1, as defined in RFC6020.
29 VERSION_1("1", "RFC6020"),
31 * Version 1.1, as defined in RFC7950.
33 VERSION_1_1("1.1", "RFC7950");
35 private static final Map<String, YangVersion> YANG_VERSION_MAP = Maps.uniqueIndex(Arrays.asList(values()),
36 YangVersion::toString);
38 private final @NonNull String str;
39 private final @NonNull String reference;
41 YangVersion(final @NonNull String str, final @NonNull String reference) {
42 this.str = requireNonNull(str);
43 this.reference = requireNonNull(reference);
47 * Parse a YANG version from its textual representation.
49 * @param str String to parse
50 * @return YANG version
51 * @throws NullPointerException if the string is null
53 public static Optional<YangVersion> parse(final @NonNull String str) {
54 return Optional.ofNullable(YANG_VERSION_MAP.get(requireNonNull(str)));
58 * Return the normative reference defining this YANG version.
60 * @return Normative reference.
62 public @NonNull String getReference() {
67 public @NonNull String toString() {