Introduce RootDeclaredStatement
[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 argument) {
42         this.argument = requireNonNull(argument);
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      * 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.
58      *
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}
62      */
63     public static @Nullable DeviateKind forArgument(final String argument) {
64         return switch (argument) {
65             case "not-supported" -> NOT_SUPPORTED;
66             case "add" -> ADD;
67             case "replace" -> REPLACE;
68             case "delete" -> DELETE;
69             default -> null;
70         };
71     }
72
73     /**
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
76      * illegal values.
77      *
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
82      */
83     public static DeviateKind ofArgument(final String argument) {
84         final var ret = forArgument(argument);
85         if (ret == null) {
86             throw new IllegalArgumentException("\"" + argument + "\" is not a valid deviate statement argument");
87         }
88         return ret;
89     }
90 }