X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=protocol%2Frestconf-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fapi%2Fquery%2FDepthParam.java;fp=protocol%2Frestconf-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fapi%2Fquery%2FDepthParam.java;h=d478d3e951db32d9f2941bea61906dbaa501eed1;hb=b372a543d9da95b9dd976fb757462f437031dde4;hp=2ee241ef0d41dbfd73df15cc0861f69b8cef2f08;hpb=62fef15fa2b0b90cae6d34135bbc52fe180f598f;p=netconf.git diff --git a/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/query/DepthParam.java b/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/query/DepthParam.java index 2ee241ef0d..d478d3e951 100644 --- a/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/query/DepthParam.java +++ b/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/query/DepthParam.java @@ -7,8 +7,6 @@ */ package org.opendaylight.restconf.api.query; -import static com.google.common.base.Preconditions.checkArgument; - import java.net.URI; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -23,18 +21,26 @@ public final class DepthParam implements RestconfQueryParam { public static final @NonNull String uriName = "depth"; private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:depth:1.0"); - private static final @NonNull DepthParam MIN = of(1); - private static final @NonNull DepthParam MAX = of(65535); + private static final @NonNull DepthParam MIN = new DepthParam(1); + private static final @NonNull DepthParam MAX = new DepthParam(65535); private final int value; private DepthParam(final int value) { this.value = value; - checkArgument(value >= 1 && value <= 65535); } public static @NonNull DepthParam of(final int value) { - return new DepthParam(value); + return switch (value) { + case 1 -> min(); + case 65535 -> max(); + default -> { + if (value < 1 || value > 65535) { + throw new IllegalArgumentException(value + " is not between 1 and 65535"); + } + yield new DepthParam(value); + } + }; } @Override @@ -61,7 +67,25 @@ public final class DepthParam implements RestconfQueryParam { } public static @Nullable DepthParam forUriValue(final String uriValue) { - return "unbounded".equals(uriValue) ? null : of(Integer.parseUnsignedInt(uriValue, 10)); + if ("unbounded".equals(uriValue)) { + return null; + } + + final int value; + try { + value = Integer.parseUnsignedInt(uriValue, 10); + } catch (NumberFormatException e) { + throw new IllegalArgumentException( + "The depth parameter must be \"unbounded\" or an integer between 1 and 65535. \"" + + uriValue + "\" is not a valid integer", e); + } + try { + return of(value); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException( + "The depth parameter must be \"unbounded\" or an integer between 1 and 65535. " + + e.getMessage(), e); + } } public int value() {