Clarify NotificationQueryParams checks 34/107734/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 6 Sep 2023 17:20:45 +0000 (19:20 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 6 Sep 2023 17:29:04 +0000 (19:29 +0200)
Using checkArgument() involves logical negation of the condition with
respect the message. This can get quite daunting when trying to
understand.

Switch to using plain if() statements, which make the logic much
clearer.

Also tie the messages to uri names, so users get clearer guidance.

Change-Id: I659921075fe3c9e4e234a86bceba24a771a1cf89
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java

index 40f13e6749ab54ec9d313695a38f1a164ef6bdc8..ae586892af10b5f4e521fc97abfff3dca9b57a74 100644 (file)
@@ -8,8 +8,6 @@
  */
 package org.opendaylight.restconf.nb.rfc8040;
 
-import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.base.MoreObjects;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
@@ -48,10 +46,14 @@ public final class NotificationQueryParams implements Immutable {
             final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
             final SkipNotificationDataParam skipNotificationData,
             final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
-        checkArgument(stopTime == null || startTime != null,
-            "Stop-time parameter has to be used with start-time parameter.");
-        checkArgument(changedLeafNodesOnly == null || leafNodesOnly == null,
-            "ChangedLeafNodesOnly parameter cannot be used with leafNodesOnlyParameter.");
+        if (stopTime != null && startTime == null) {
+            throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
+                + StartTimeParam.uriName + " parameter");
+        }
+        if (changedLeafNodesOnly != null && leafNodesOnly != null) {
+            throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
+                + LeafNodesOnlyParam.uriName + " parameter");
+        }
         return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
                 changedLeafNodesOnly);
     }