5 commented on code in PR #81:
URL: https://github.com/apache/cassandra-sidecar/pull/81#discussion_r1468186439
##########
common/src/main/java/org/apache/cassandra/sidecar/common/utils/TimeUtils.java:
##########
@@ -0,0 +1,36 @@
+package org.apache.cassandra.sidecar.common.utils;
+
+import java.time.Duration;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Utility class for manipulating dates, times, and durations
+ */
+public final class TimeUtils {
+ /**
+ * Private constructor that prevents unnecessary instantiation
+ *
+ * @throws IllegalStateException when called
+ */
+ private TimeUtils()
+ {
+ throw new IllegalStateException(getClass() + " is a static utility
class and shall not be instantiated");
+ }
+
+ /**
+ * Returns a random duration with millisecond precision that is uniformly
distributed between two provided durations
+ *
+ * @param minimum minimum possible duration, inclusive
+ * @param maximum maximum possible duration, inclusive
+ *
+ * @return random duration uniformly distributed between two provided
durations, with millisecond precision
+ *
+ * @throws IllegalArgumentException if minimum duration is greater than
maximum duration
+ */
+ public static Duration randomDuration(Duration minimum, Duration maximum)
+ {
+ Preconditions.checkArgument(minimum.compareTo(maximum) <= 0,
+ "Minimum duration must be less or equal to
maximum duration");
+ return
Duration.ofMillis(ThreadLocalRandom.current().nextLong(minimum.toMillis(),
maximum.toMillis() + 1L));
Review Comment:
I did make that change, but, to be honest, I didn't like what the code
became.
Right now, "minimum duration" and "maximum duration" are easy to understand
and explain.
With the change, "minimum duration" stays, but the actual meaning of the
other value becomes confusing, at least to me.
"Maximum number of milliseconds to add on top of minimum duration" is a
mouthful, and still needs to be checked for being non-negative.
Can we please keep the current implementation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]