6594c6b472b5c4f77dce5f8b1126c0a2f68523a9
[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
14 /**
15  * Enumeration of possible {@code insert} values as defined by
16  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.5">RFC8040, section 4.8.5</a>.
17  */
18 public enum InsertParam implements RestconfQueryParam<InsertParam> {
19     /**
20      * Insert the new data after the insertion point, as specified by the value of the "point" parameter.
21      */
22     AFTER("after"),
23     /**
24      * Insert the new data before the insertion point, as specified by the value of the "point" parameter.
25      */
26     BEFORE("before"),
27     /**
28      * Insert the new data as the new first entry.
29      */
30     FIRST("first"),
31     /**
32      * Insert the new data as the new last entry.
33      */
34     LAST("last");
35
36     // API consistency: must not be confused with enum constants
37     @SuppressWarnings("checkstyle:ConstantName")
38     public static final @NonNull String uriName = "insert";
39
40     private @NonNull String uriValue;
41
42     InsertParam(final String uriValue) {
43         this.uriValue = requireNonNull(uriValue);
44     }
45
46     @Override
47     public Class<@NonNull InsertParam> javaClass() {
48         return InsertParam.class;
49     }
50
51     @Override
52     public String paramName() {
53         return uriName;
54     }
55
56     @Override
57     public String paramValue() {
58         return uriValue;
59     }
60
61     public static @NonNull InsertParam forUriValue(final String uriValue) {
62         switch (uriValue) {
63             case "after":
64                 return AFTER;
65             case "before":
66                 return BEFORE;
67             case "first":
68                 return FIRST;
69             case "last":
70                 return LAST;
71             default:
72                 throw new IllegalArgumentException(
73                     "Value can be 'after', 'before', 'first' or 'last', not '" + uriValue + "'");
74         }
75     }
76 }