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