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.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 {@code deviate}
17 * <a href="https://www.rfc-editor.org/rfc/rfc7950.html#section-7.20.3.2">YANG statement</a> argument. It defines how
18 * the server implementation of the target node deviates from its original definition.
21 public enum DeviateKind {
23 * Target node is not implemented by the server.
25 NOT_SUPPORTED("not-supported"),
27 * Server implements target node with additional properties.
31 * Server implements target node with different properties.
35 * Server implements target node without some properties.
39 private final String argument;
41 DeviateKind(final String argumentValue) {
42 argument = requireNonNull(argumentValue);
46 * Returns the YANG {@code deviate} statement argument value corresponding to this object.
48 * @return String that corresponds to the YANG {@code deviate} statement argument
50 public String argument() {
55 * Returns the YANG keyword corresponding to this object.
57 * @return String that corresponds to the YANG keyword.
58 * @deprecated Use {@link #argument} instead.
60 @Deprecated(since = "9.0.0", forRemoval = true)
61 public String getKeyword() {
66 * Return a {@link DeviateKind} for specified {@code deviate} statement argument. This methods returns a
67 * {@code null} for illegal values. See {@link #ofArgument(String)} for a version which returns non-null and throws
68 * an exception for illegal values.
70 * @param argument {@code deviate} statement argument
71 * @return An enumeration value, or {@code null} if specified argument is not valid
72 * @throws NullPointerException if {@code argument} is {@code null}
74 public static @Nullable DeviateKind forArgument(final String argument) {
75 return switch (argument) {
76 case "not-supported" -> NOT_SUPPORTED;
78 case "replace" -> REPLACE;
79 case "delete" -> DELETE;
85 * Return a {@link DeviateKind} for specified {@code deviate} statement argument. This methods throws an exception
86 * for illegal values. See {@link #forArgument(String)} for a version which returns a {@code null} instead for
89 * @param argument {@code deviate} statement argument
90 * @return An enumeration value
91 * @throws NullPointerException if {@code argument} is {@code null}
92 * @throws IllegalArgumentException if {@code argument} is not a valid {@code deviate} statement argument
94 public static DeviateKind ofArgument(final String argument) {
95 final var ret = forArgument(argument);
97 throw new IllegalArgumentException("\"" + argument + "\" is not a valid deviate statement argument");