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