4c60198c8687769984b490cc0e46d954d353be8b
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / InsertParam.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 insert} 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 InsertParam implements RestconfQueryParam<InsertParam> {
20     /**
21      * Insert the new data after the insertion point, as specified by the value of the "point" parameter.
22      */
23     AFTER("after"),
24     /**
25      * Insert the new data before the insertion point, as specified by the value of the "point" parameter.
26      */
27     BEFORE("before"),
28     /**
29      * Insert the new data as the new first entry.
30      */
31     FIRST("first"),
32     /**
33      * Insert the new data as the new last entry.
34      */
35     LAST("last");
36
37     // API consistency: must not be confused with enum constants
38     @SuppressWarnings("checkstyle:ConstantName")
39     public static final @NonNull String uriName = "insert";
40
41     private @NonNull String uriValue;
42
43     InsertParam(final String uriValue) {
44         this.uriValue = requireNonNull(uriValue);
45     }
46
47     @Override
48     public Class<@NonNull InsertParam> javaClass() {
49         return InsertParam.class;
50     }
51
52     @Override
53     public String paramName() {
54         return uriName;
55     }
56
57     @Override
58     public String paramValue() {
59         return uriValue;
60     }
61
62     // Note: returns null of unknowns
63     public static @Nullable InsertParam forUriValue(final String uriValue) {
64         switch (uriValue) {
65             case "after":
66                 return AFTER;
67             case "before":
68                 return BEFORE;
69             case "first":
70                 return FIRST;
71             case "last":
72                 return LAST;
73             default:
74                 return null;
75         }
76     }
77 }