ce25524e0015eef2303dcf7472267d6097d5ace9
[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 java.net.URI;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.concepts.Immutable;
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 DepthParameter implements Immutable {
22     private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:depth:1.0");
23
24     private final int value;
25
26     private DepthParameter(final int value) {
27         this.value = value;
28         checkArgument(value >= 1 && value <= 65535);
29     }
30
31     public static DepthParameter of(final int value) {
32         return new DepthParameter(value);
33     }
34
35     public static @Nullable DepthParameter forUriValue(final String uriValue) {
36         return uriValue.equals("unbounded") ? null : of(Integer.parseUnsignedInt(uriValue, 10));
37     }
38
39     public int value() {
40         return value;
41     }
42
43     public static @NonNull String uriName() {
44         return "depth";
45     }
46
47     public @NonNull String uriValue() {
48         return String.valueOf(value);
49     }
50
51     public static @NonNull URI capabilityUri() {
52         return CAPABILITY;
53     }
54 }