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.NonNullByDefault;
20 * Enumeration of supported YANG versions.
22 * @author Robert Varga
26 public enum YangVersion {
28 * Version 1, as defined in RFC6020.
30 VERSION_1("1", "RFC6020"),
32 * Version 1.1, as defined in RFC7950.
34 VERSION_1_1("1.1", "RFC7950");
36 private static final Map<String, YangVersion> YANG_VERSION_MAP = Maps.uniqueIndex(Arrays.asList(values()),
37 YangVersion::toString);
39 private final String str;
40 private String reference;
42 YangVersion(final String str, final String reference) {
43 this.str = requireNonNull(str);
44 this.reference = requireNonNull(reference);
48 * Parse a YANG version from its textual representation.
50 * @param str String to parse
51 * @return YANG version
52 * @throws NullPointerException if the string is null
54 public static Optional<YangVersion> parse(final String str) {
55 return Optional.ofNullable(YANG_VERSION_MAP.get(requireNonNull(str)));
59 * Return the normative reference defining this YANG version.
61 * @return Normative reference.
63 public String getReference() {
68 public String toString() {