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 com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
13 import java.util.Arrays;
15 import java.util.Optional;
16 import javax.annotation.Nonnull;
19 * Enumeration of supported YANG versions.
21 * @author Robert Varga
24 public enum YangVersion {
26 * Version 1, as defined in RFC6020.
28 VERSION_1("1", "RFC6020"),
30 * Version 1.1, as defined in RFC7950.
32 VERSION_1_1("1.1", "RFC7950");
34 private static final Map<String, YangVersion> YANG_VERSION_MAP = Maps.uniqueIndex(Arrays.asList(values()),
35 YangVersion::toString);
37 private final String str;
38 private String reference;
40 YangVersion(final String str, final String reference) {
41 this.str = Preconditions.checkNotNull(str);
42 this.reference = Preconditions.checkNotNull(reference);
46 * Parse a YANG version from its textual representation.
48 * @param str String to parse
49 * @return YANG version
50 * @throws NullPointerException if the string is null
52 public static Optional<YangVersion> parse(@Nonnull final String str) {
53 return Optional.ofNullable(YANG_VERSION_MAP.get(Preconditions.checkNotNull(str)));
57 * Return the normative reference defining this YANG version.
59 * @return Normative reference.
61 @Nonnull public String getReference() {
66 @Nonnull public String toString() {