Make a few methods static
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / RestconfDataServiceConstant.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.restconf.nb.rfc8040.rests.utils;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableMap;
13 import com.google.common.collect.Maps;
14 import java.util.Arrays;
15 import java.util.Set;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 /**
22  * Constants for RestconfDataService.
23  *
24  */
25 public final class RestconfDataServiceConstant {
26     public static final QName NETCONF_BASE_QNAME = SchemaContext.NAME;
27
28     private RestconfDataServiceConstant() {
29         // Hidden on purpose
30     }
31
32     /**
33      * Constants for read data.
34      *
35      */
36     public static final class ReadData {
37         // URI parameters
38         public static final String CONTENT = "content";
39         public static final String DEPTH = "depth";
40         public static final String FIELDS = "fields";
41
42         // content values
43         public static final String CONFIG = "config";
44         public static final String ALL = "all";
45         public static final String NONCONFIG = "nonconfig";
46
47         // depth values
48         public static final String UNBOUNDED = "unbounded";
49         public static final int MIN_DEPTH = 1;
50         public static final int MAX_DEPTH = 65535;
51
52         public static final String WITH_DEFAULTS = "with-defaults";
53
54         /**
55          * With-default values, as per
56          * <a href="https://tools.ietf.org/html/rfc8040#section-4.8.9">RFC8040 section 4.8.9</a>.
57          */
58         enum WithDefaults {
59             /**
60              * All data nodes are reported.
61              */
62             REPORT_ALL("report-all"),
63             /**
64              * Data nodes set to the YANG default are not reported.
65              */
66             TRIM("trim"),
67             /**
68              * Data nodes set to the YANG default by the client are reported.
69              */
70             EXPLICIT("explicit"),
71             /**
72              * All data nodes are reported, and defaults are tagged.
73              */
74             REPORT_ALL_TAGGED("report-all-tagged");
75
76             private static final ImmutableMap<String, WithDefaults> VALUES =
77                 Maps.uniqueIndex(Arrays.asList(values()), WithDefaults::value);
78
79             private @NonNull String value;
80
81             WithDefaults(final @NonNull String value) {
82                 this.value = value;
83             }
84
85             public @NonNull String value() {
86                 return value;
87             }
88
89             static @Nullable WithDefaults forValue(final String value) {
90                 return VALUES.get(requireNonNull(value));
91             }
92
93             static @Nullable Set<String> possibleValues() {
94                 return VALUES.keySet();
95             }
96         }
97
98         private ReadData() {
99             // Hidden on purpose
100         }
101     }
102
103     /**
104      * Common for PostData and PutData.
105      */
106     public static final class PostPutQueryParameters {
107         public static final String INSERT = "insert";
108         public static final String POINT = "point";
109
110         /**
111          * Insert values, as per <a href="https://tools.ietf.org/html/rfc8040#section-4.8.5">RFC8040 section 4.8.5</a>.
112          */
113         public enum Insert {
114             /**
115              * Insert the new data as the new first entry.
116              */
117             FIRST("first"),
118             /**
119              * Insert the new data as the new last entry.
120              */
121             LAST("last"),
122             /**
123              * Insert the new data before the insertion point, as specified by the value of the "point" parameter.
124              */
125             BEFORE("before"),
126             /**
127              * Insert the new data after the insertion point, as specified by the value of the "point" parameter.
128              */
129             AFTER("after");
130
131             private static final ImmutableMap<String, Insert> VALUES =
132                 Maps.uniqueIndex(Arrays.asList(values()), Insert::value);
133
134             private @NonNull String value;
135
136             Insert(final @NonNull String value) {
137                 this.value = value;
138             }
139
140             public @NonNull String value() {
141                 return value;
142             }
143
144             public static @Nullable Insert forValue(final String value) {
145                 return VALUES.get(requireNonNull(value));
146             }
147         }
148
149         private PostPutQueryParameters() {
150             // Hidden on purpose
151         }
152     }
153 }