Reduce exception guard
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / ContentParam.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.restconf.nb.rfc8040;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13
14 /**
15  * Enumeration of possible {@code content} values as defined by
16  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.1">RFC8040, section 4.8.1</a>.
17  */
18 public enum ContentParam implements RestconfQueryParam<ContentParam> {
19     /**
20      * Return all descendant data nodes.
21      */
22     ALL("all"),
23     /**
24      * Return only configuration descendant data nodes.
25      */
26     CONFIG("config"),
27     /**
28      * Return only non-configuration descendant data nodes.
29      */
30     NONCONFIG("nonconfig");
31
32     // API consistency: must not be confused with enum constants
33     @SuppressWarnings("checkstyle:ConstantName")
34     public static final @NonNull String uriName = "content";
35
36     private final @NonNull String uriValue;
37
38     ContentParam(final String uriValue) {
39         this.uriValue = requireNonNull(uriValue);
40     }
41
42     @Override
43     public final Class<@NonNull ContentParam> javaClass() {
44         return ContentParam.class;
45     }
46
47     @Override
48     public final String paramName() {
49         return uriName;
50     }
51
52     @Override
53     public String paramValue() {
54         return uriValue;
55     }
56
57     public static @NonNull ContentParam forUriValue(final String uriValue) {
58         switch (uriValue) {
59             case "all":
60                 return ALL;
61             case "config":
62                 return CONFIG;
63             case "nonconfig":
64                 return NONCONFIG;
65             default:
66                 throw new IllegalArgumentException(
67                     "Value can be 'all', 'config' or 'nonconfig', not '" + uriValue + "'");
68         }
69     }
70 }