GutoVeronezi commented on code in PR #6704:
URL: https://github.com/apache/cloudstack/pull/6704#discussion_r1033519440


##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -1823,6 +1823,26 @@ private Volume 
changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
         return volume;
     }
 
+    /**
+     * This method is to compare long values, in miniops and maxiops a or b 
can be null or 0.
+     * Use this method to treat 0 and null as same
+     *
+     * @param a
+     * @param b
+     * @return true if a and b are equal excluding 0 and null values.
+     */
+    private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
+        if ((a != null && a == 0 && b == null) || (a == null && b != null && b 
== 0)) {
+            return true;
+        }
+
+        if (a == b) {
+            return true;
+        }
+
+        return false;
+    }

Review Comment:
   We could moved this method to `NumbersUtils` and add unit tests.
   
   As zero and null will be considered the same, we can simplify the code:
   
   `org.apache.commons.lang3.ObjectUtils`
   
   ```suggestion
       private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
           a = ObjectUtils.defaultIfNull(a, 0L);
           b = ObjectUtils.defaultIfNull(b, 0L);
   
           return a.equals(b);
       }
   ```



##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -1823,6 +1823,26 @@ private Volume 
changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
         return volume;
     }
 
+    /**
+     * This method is to compare long values, in miniops and maxiops a or b 
can be null or 0.
+     * Use this method to treat 0 and null as same
+     *
+     * @param a
+     * @param b
+     * @return true if a and b are equal excluding 0 and null values.
+     */
+    private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
+        if ((a != null && a == 0 && b == null) || (a == null && b != null && b 
== 0)) {
+            return true;
+        }
+
+        if (a == b) {
+            return true;
+        }
+
+        return false;
+    }

Review Comment:
   We could move this method to `NumbersUtils` and add unit tests.
   
   As zero and null will be considered the same, we can simplify the code:
   
   `org.apache.commons.lang3.ObjectUtils`
   
   ```suggestion
       private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
           a = ObjectUtils.defaultIfNull(a, 0L);
           b = ObjectUtils.defaultIfNull(b, 0L);
   
           return a.equals(b);
       }
   ```



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

Reply via email to