2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.restconf.api.query;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
15 * This class represents a {@code depth} parameter as defined in
16 * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.8.2">RFC8040 section 4.8.2</a>.
18 public final class DepthParam implements RestconfQueryParam<DepthParam> {
19 // API consistency: must not be confused with enum constants
20 @SuppressWarnings("checkstyle:ConstantName")
21 public static final @NonNull String uriName = "depth";
23 private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:depth:1.0");
24 private static final @NonNull DepthParam MIN = new DepthParam(1);
25 private static final @NonNull DepthParam MAX = new DepthParam(65535);
27 private final int value;
29 private DepthParam(final int value) {
33 public static @NonNull DepthParam of(final int value) {
34 return switch (value) {
38 if (value < 1 || value > 65535) {
39 throw new IllegalArgumentException(value + " is not between 1 and 65535");
41 yield new DepthParam(value);
47 public Class<DepthParam> javaClass() {
48 return DepthParam.class;
52 public String paramName() {
57 public String paramValue() {
58 return String.valueOf(value);
61 public static @NonNull DepthParam min() {
65 public static @NonNull DepthParam max() {
69 public static @Nullable DepthParam forUriValue(final String uriValue) {
70 if ("unbounded".equals(uriValue)) {
76 value = Integer.parseUnsignedInt(uriValue, 10);
77 } catch (NumberFormatException e) {
78 throw new IllegalArgumentException(
79 "The depth parameter must be \"unbounded\" or an integer between 1 and 65535. \""
80 + uriValue + "\" is not a valid integer", e);
84 } catch (IllegalArgumentException e) {
85 throw new IllegalArgumentException(
86 "The depth parameter must be \"unbounded\" or an integer between 1 and 65535. "
95 public static @NonNull URI capabilityUri() {