Link to SchemaNodeIdentifier
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / DeviateKind.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
14
15 /**
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.
19  */
20 @NonNullByDefault
21 public enum DeviateKind {
22     /**
23      * Target node is not implemented by the server.
24      */
25     NOT_SUPPORTED("not-supported"),
26     /**
27      * Server implements target node with additional properties.
28      */
29     ADD("add"),
30     /**
31      * Server implements target node with different properties.
32      */
33     REPLACE("replace"),
34     /**
35      * Server implements target node without some properties.
36      */
37     DELETE("delete");
38
39     private final String argument;
40
41     DeviateKind(final String argumentValue) {
42         argument = requireNonNull(argumentValue);
43     }
44
45     /**
46      * Returns the YANG {@code deviate} statement argument value corresponding to this object.
47      *
48      * @return String that corresponds to the YANG {@code deviate} statement argument
49      */
50     public String argument() {
51         return argument;
52     }
53
54     /**
55      * Returns the YANG keyword corresponding to this object.
56      *
57      * @return String that corresponds to the YANG keyword.
58      * @deprecated Use {@link #argument} instead.
59      */
60     @Deprecated(since = "9.0.0", forRemoval = true)
61     public String getKeyword() {
62         return argument;
63     }
64
65     /**
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.
69      *
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}
73      */
74     public static @Nullable DeviateKind forArgument(final String argument) {
75         return switch (argument) {
76             case "not-supported" -> NOT_SUPPORTED;
77             case "add" -> ADD;
78             case "replace" -> REPLACE;
79             case "delete" -> DELETE;
80             default -> null;
81         };
82     }
83
84     /**
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
87      * illegal values.
88      *
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
93      */
94     public static DeviateKind ofArgument(final String argument) {
95         final var ret = forArgument(argument);
96         if (ret == null) {
97             throw new IllegalArgumentException("\"" + argument + "\" is not a valid deviate statement argument");
98         }
99         return ret;
100     }
101 }