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 argument) {
42 this.argument = requireNonNull(argument);
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 * Return a {@link DeviateKind} for specified {@code deviate} statement argument. This methods returns a
56 * {@code null} for illegal values. See {@link #ofArgument(String)} for a version which returns non-null and throws
57 * an exception for illegal values.
59 * @param argument {@code deviate} statement argument
60 * @return An enumeration value, or {@code null} if specified argument is not valid
61 * @throws NullPointerException if {@code argument} is {@code null}
63 public static @Nullable DeviateKind forArgument(final String argument) {
64 return switch (argument) {
65 case "not-supported" -> NOT_SUPPORTED;
67 case "replace" -> REPLACE;
68 case "delete" -> DELETE;
74 * Return a {@link DeviateKind} for specified {@code deviate} statement argument. This methods throws an exception
75 * for illegal values. See {@link #forArgument(String)} for a version which returns a {@code null} instead for
78 * @param argument {@code deviate} statement argument
79 * @return An enumeration value
80 * @throws NullPointerException if {@code argument} is {@code null}
81 * @throws IllegalArgumentException if {@code argument} is not a valid {@code deviate} statement argument
83 public static DeviateKind ofArgument(final String argument) {
84 final var ret = forArgument(argument);
86 throw new IllegalArgumentException("\"" + argument + "\" is not a valid deviate statement argument");