2 * Copyright (c) 2013 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.api;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
16 * Enumeration describing YANG 'status' statement. If no status is specified, the
22 * CURRENT means that the definition is current and valid.
26 * DEPRECATED indicates an obsolete definition, but it permits new/
27 * continued implementation in order to foster interoperability with
28 * older/existing implementations.
30 DEPRECATED("deprecated"),
32 * OBSOLETE means the definition is obsolete and SHOULD NOT be implemented
33 * and/or can be removed from implementations.
37 private final String argument;
39 Status(final String argument) {
40 this.argument = requireNonNull(argument);
44 * Returns the YANG {@code status} statement argument value corresponding to this object.
46 * @return String that corresponds to the YANG {@code status} statement argument
48 public String argument() {
53 * Return a {@link Status} for specified {@code status} statement argument. This methods returns a {@code null} for
54 * illegal values. See {@link #ofArgument(String)} for a version which returns non-null and throws an exception for
57 * @param argument {@code status} statement argument
58 * @return An enumeration value, or {@code null} if specified argument is not valid
59 * @throws NullPointerException if {@code argument} is {@code null}
61 public static @Nullable Status forArgument(final String argument) {
62 return switch (argument) {
63 case "current" -> CURRENT;
64 case "deprecated" -> DEPRECATED;
65 case "obsolete" -> OBSOLETE;
71 * Return a {@link Status} for specified {@code status} statement argument. This methods throws an exception for
72 * illegal values. See {@link #forArgument(String)} for a version which returns a {@code null} instead for illegal
75 * @param argument {@code status} statement argument
76 * @return An enumeration value, or {@code null} if specified argument is not valid
77 * @throws NullPointerException if {@code argument} is {@code null}
78 * @throws IllegalArgumentException if {@code argument} is not a valid {@code status} statement argument
80 public static Status ofArgument(final String argument) {
81 final var ret = forArgument(argument);
83 throw new IllegalArgumentException("\"" + argument + "\" is not a valid status statement argument");