Clarify NotificationQueryParams checks 44/108344/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 6 Sep 2023 17:20:45 +0000 (19:20 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Oct 2023 08:42:11 +0000 (10:42 +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>
(cherry picked from commit 6b828e1710315104da40e750cc0c85593183bc68)
(cherry picked from commit 0ba2548351b626286902fcaadf87af838e6433cd)
(cherry picked from commit 024ef99ebba00f5f755f5ad30fd2c01376ca050e)

restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java

index 680057d2b53656f0e7d606a3e236df9abc9db6dc..b5c81c853b429d3b7ffd3d1327cf33ddf28267ab 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;
@@ -38,8 +36,10 @@ public final class NotificationQueryParams implements Immutable {
     public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
             final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
             final SkipNotificationDataParam skipNotificationData) {
-        checkArgument(stopTime == null || startTime != null,
-            "Stop-time parameter has to be used with start-time parameter.");
+        if (stopTime != null && startTime == null) {
+            throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
+                + StartTimeParam.uriName + " parameter");
+        }
         return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData);
     }