Copilot commented on code in PR #11316:
URL: https://github.com/apache/cloudstack/pull/11316#discussion_r2238395434
##########
api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java:
##########
@@ -129,6 +129,8 @@ public int compare(CapacityResponse resp1, CapacityResponse
resp2) {
int res = resp1.getZoneName().compareTo(resp2.getZoneName());
if (res != 0) {
return res;
+ } else if (getSortBy() != null) {
+ return 0;
Review Comment:
Returning 0 when sortBy is not null breaks the sorting functionality. The
comparator should delegate to the appropriate sorting logic based on the sortBy
parameter value instead of treating equal zone names as equal elements.
```suggestion
switch (getSortBy()) {
case "capacityUsed":
return Long.compare(resp1.getCapacityUsed(),
resp2.getCapacityUsed());
case "capacityTotal":
return Long.compare(resp1.getCapacityTotal(),
resp2.getCapacityTotal());
case "percentUsed":
return Double.compare(resp1.getPercentUsed(),
resp2.getPercentUsed());
default:
throw new
InvalidParameterValueException("Invalid sortBy parameter: " + getSortBy());
}
```
--
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]