Reduce exception guard
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / SkipNotificationDataParam.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 java.net.URI;
11 import org.eclipse.jdt.annotation.NonNull;
12
13 /**
14  * OpenDaylight extension parameter. When used as {@code odl-skip-notification-data=true}, it will instruct the listener
15  * streams to prune data from notifications.
16  */
17 public final class SkipNotificationDataParam implements RestconfQueryParam<SkipNotificationDataParam> {
18     // API consistency: must not be confused with enum constants
19     @SuppressWarnings("checkstyle:ConstantName")
20     public static final String uriName = "odl-skip-notification-data";
21
22     private static final @NonNull URI CAPABILITY =
23         URI.create("urn:opendaylight:params:restconf:capability:skip-notification-data:1.0");
24     private static final @NonNull SkipNotificationDataParam FALSE = new SkipNotificationDataParam(false);
25     private static final @NonNull SkipNotificationDataParam TRUE = new SkipNotificationDataParam(true);
26
27     private final boolean value;
28
29     private SkipNotificationDataParam(final boolean value) {
30         this.value = value;
31     }
32
33     public static @NonNull SkipNotificationDataParam of(final boolean value) {
34         return value ? TRUE : FALSE;
35     }
36
37     public static @NonNull SkipNotificationDataParam forUriValue(final String uriValue) {
38         switch (uriValue) {
39             case "false":
40                 return FALSE;
41             case "true":
42                 return TRUE;
43             default:
44                 throw new IllegalArgumentException("Value can be 'false' or 'true', not '" + uriValue + "'");
45         }
46     }
47
48     @Override
49     public Class<@NonNull SkipNotificationDataParam> javaClass() {
50         return SkipNotificationDataParam.class;
51     }
52
53     @Override
54     public String paramName() {
55         return uriName;
56     }
57
58     @Override
59     public String paramValue() {
60         return String.valueOf(value);
61     }
62
63     public boolean value() {
64         return value;
65     }
66
67     public static @NonNull URI capabilityUri() {
68         return CAPABILITY;
69     }
70 }