ekaterinadimitrova2 commented on a change in pull request #1425:
URL: https://github.com/apache/cassandra/pull/1425#discussion_r795299354



##########
File path: src/java/org/apache/cassandra/config/DurationSpec.java
##########
@@ -53,86 +57,112 @@ public Duration(String value)
 
         //parse the string field value
         Matcher matcher = TIME_UNITS_PATTERN.matcher(value);
-        Matcher matcherDouble = DOUBLE_TIME_UNITS_PATTERN.matcher(value);
 
         if(matcher.find())
         {
             quantity = Long.parseLong(matcher.group(1));
             unit = fromSymbol(matcher.group(2));
         }
-        else if(matcherDouble.find())
+        else
         {
-            quantity =(long) Double.parseDouble(matcherDouble.group(1));
-            unit = fromSymbol(matcherDouble.group(2));
-        }
-        else {
-            throw new IllegalArgumentException("Invalid duration: " + value);
+            throw new ConfigurationException("Invalid duration: " + value + " 
Accepted units: d, h, m, s, ms, us, µs," +
+                                             " ns where case matters and " + 
"only non-negative values");
         }
     }
 
-    private Duration(long quantity, TimeUnit unit)
+    DurationSpec(long quantity, TimeUnit unit)
     {
         if (quantity < 0)
-            throw new IllegalArgumentException("Duration must be positive");
+            throw new ConfigurationException("Invalid duration: value must be 
positive");
 
         this.quantity = quantity;
         this.unit = unit;
     }
 
-    private Duration(double quantity, TimeUnit unit)
+    private DurationSpec(double quantity, TimeUnit unit)
     {
-        if (quantity < 0)
-            throw new IllegalArgumentException("Duration must be positive");
-
-        this.quantity = (long) quantity;
-        this.unit = unit;
+        this(Math.round(quantity), unit);
     }
 
     /**
-     * Creates a {@code Duration} of the specified amount of milliseconds.
+     * Creates a {@code DurationSpec} of the specified amount of milliseconds.
      *
      * @param milliseconds the amount of milliseconds
      * @return a duration
      */
-    public static Duration inMilliseconds(long milliseconds)
+    public static DurationSpec inMilliseconds(long milliseconds)
     {
-        return new Duration(milliseconds, TimeUnit.MILLISECONDS);
+        return new DurationSpec(milliseconds, TimeUnit.MILLISECONDS);
     }
 
-    public static Duration inDoubleMilliseconds(double milliseconds)
+    public static DurationSpec inDoubleMilliseconds(double milliseconds)
     {
-        return new Duration(milliseconds, TimeUnit.MILLISECONDS);
+        return new DurationSpec(milliseconds, TimeUnit.MILLISECONDS);
     }
 
     /**
-     * Creates a {@code Duration} of the specified amount of seconds.
+     * Creates a {@code DurationSpec} of the specified amount of seconds.
      *
      * @param seconds the amount of seconds
      * @return a duration
      */
-    public static Duration inSeconds(long seconds)
+    public static DurationSpec inSeconds(long seconds)
     {
-        return new Duration(seconds, TimeUnit.SECONDS);
+        return new DurationSpec(seconds, TimeUnit.SECONDS);
     }
 
     /**
-     * Creates a {@code Duration} of the specified amount of minutes.
+     * Creates a {@code DurationSpec} of the specified amount of minutes.
      *
      * @param minutes the amount of minutes
      * @return a duration
      */
-    public static Duration inMinutes(long minutes)
+    public static DurationSpec inMinutes(long minutes)
     {
-        return new Duration(minutes, TimeUnit.MINUTES);
+        return new DurationSpec(minutes, TimeUnit.MINUTES);
     }
 
     /**
-     * Returns the time unit associated to the specified symbol
+     * Creates a {@code DurationSpec} of the specified amount of hours.
      *
+     * @param hours the amount of hours
+     * @return a duration
+     */
+    public static DurationSpec inHours(long hours)
+    {
+        return new DurationSpec(hours, TimeUnit.HOURS);
+    }
+
+    /**
+     * Creates a {@code DurationSpec} of the specified amount of seconds. 
Custom method for special cases.
+     *
+     * @param value which can be in the old form only presenting the quantity 
or the post CASSANDRA-15234 form - a
+     * value consisting of quantity and unit. This method is necessary for 
three parameters which didn't change their
+     * names but only their value format. (key_cache_save_period, 
row_cache_save_period, counter_cache_save_period)
+     * @return a duration
+     */
+    public static DurationSpec inSecondsString(String value)
+    {
+        //parse the string field value
+        Matcher matcher = VALUES_PATTERN.matcher(value);
+
+        long seconds;
+        //if the provided string value is just a number, then we create a 
Duration Spec value in seconds
+        if (matcher.find())

Review comment:
       wrong function, we should use, I changed it pre-commit: 
         ```
   if (matcher.matches())
            {
                seconds = Long.parseLong(value);
                return new DurationSpec(seconds, TimeUnit.SECONDS);
            }
   ```




-- 
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]

Reply via email to