Add RestconfQueryParam
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / DepthParam.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 com.google.common.base.Preconditions.checkArgument;
11
12 import com.google.common.annotations.Beta;
13 import java.net.URI;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16
17 /**
18  * This class represents a {@code depth} parameter as defined in
19  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.3">RFC8040 section 4.8.2</a>.
20  */
21 public final class DepthParam implements RestconfQueryParam<DepthParam> {
22     private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:depth:1.0");
23     private static final @NonNull DepthParam MIN = of(1);
24     private static final @NonNull DepthParam MAX = of(65535);
25
26     private final int value;
27
28     private DepthParam(final int value) {
29         this.value = value;
30         checkArgument(value >= 1 && value <= 65535);
31     }
32
33     public static @NonNull DepthParam of(final int value) {
34         return new DepthParam(value);
35     }
36
37     @Override
38     public Class<@NonNull DepthParam> javaClass() {
39         return DepthParam.class;
40     }
41
42     @Override
43     public String paramName() {
44         return uriName();
45     }
46
47     @Override
48     public String paramValue() {
49         return String.valueOf(value);
50     }
51
52     public static @NonNull String uriName() {
53         return "depth";
54     }
55
56     @Beta
57     public static @NonNull DepthParam min() {
58         return MIN;
59     }
60
61     @Beta
62     public static @NonNull DepthParam max() {
63         return MAX;
64     }
65
66     public static @Nullable DepthParam forUriValue(final String uriValue) {
67         return "unbounded".equals(uriValue) ? null : of(Integer.parseUnsignedInt(uriValue, 10));
68     }
69
70     public int value() {
71         return value;
72     }
73
74     public static @NonNull URI capabilityUri() {
75         return CAPABILITY;
76     }
77 }