6ed8e20f1fc19244ef12a501501beb867f8b89a8
[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 import org.eclipse.jdt.annotation.Nullable;
14
15 /**
16  * Enumeration of possible {@code content} values as defined by
17  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.1">RFC8040, section 4.8.1</a>.
18  */
19 public enum ContentParam implements RestconfQueryParam<ContentParam> {
20     /**
21      * Return all descendant data nodes.
22      */
23     ALL("all"),
24     /**
25      * Return only configuration descendant data nodes.
26      */
27     CONFIG("config"),
28     /**
29      * Return only non-configuration descendant data nodes.
30      */
31     NONCONFIG("nonconfig");
32
33     // API consistency: must not be confused with enum constants
34     @SuppressWarnings("checkstyle:ConstantName")
35     public static final @NonNull String uriName = "content";
36
37     private final @NonNull String uriValue;
38
39     ContentParam(final String uriValue) {
40         this.uriValue = requireNonNull(uriValue);
41     }
42
43     @Override
44     public final Class<@NonNull ContentParam> javaClass() {
45         return ContentParam.class;
46     }
47
48     @Override
49     public final String paramName() {
50         return uriName;
51     }
52
53     @Override
54     public String paramValue() {
55         return uriValue;
56     }
57
58     // Note: returns null of unknowns
59     public static @Nullable ContentParam forUriValue(final String uriValue) {
60         switch (uriValue) {
61             case "all":
62                 return ALL;
63             case "config":
64                 return CONFIG;
65             case "nonconfig":
66                 return NONCONFIG;
67             default:
68                 return null;
69         }
70     }
71 }