smiklosovic commented on code in PR #3733:
URL: https://github.com/apache/cassandra/pull/3733#discussion_r1883630636
##########
src/java/org/apache/cassandra/tools/nodetool/Status.java:
##########
@@ -170,24 +215,134 @@ private void addNode(String endpoint, Float owns,
HostStatWithPort hostStat, int
strOwns = owns != null && hasEffectiveOwns ? new
DecimalFormat("##0.0%").format(owns) : "?";
hostID = hostIDMap.get(endpoint);
- try
- {
+ try {
rack = epSnitchInfo.getRack(endpoint);
- }
- catch (UnknownHostException e)
- {
+ } catch (UnknownHostException e) {
throw new RuntimeException(e);
}
- epDns = hostStat.ipOrDns(printPort);
if (isTokenPerNode)
- {
- tableBuilder.add(statusAndState, epDns, load, strOwns, hostID,
hostStat.token, rack);
- }
+ return List.of(addressAndPort, statusAndState, epDns, load,
strOwns, hostID, hostStat.token, rack);
else
- {
- tableBuilder.add(statusAndState, epDns, load,
String.valueOf(size), strOwns, hostID, rack);
+ return List.of(addressAndPort, statusAndState, epDns, load,
String.valueOf(size), strOwns, hostID, rack);
+ }
+
+ // To check for descending order
+ private Boolean desc() {
+ return sortOrder == null ? null : sortOrder == SortOrder.desc;
+ }
+
+ // Sort function to sort the data
+ private Map<String, List<Object>> sort(Map<String, List<Object>> map) {
+ switch (sortBy) {
+ case none:
+ return map;
+ case ip:
+ return sortByIp(map, 0, desc() != null ? desc() : false);
Review Comment:
you can simplify this down to `return sortByIp(map)` because
1) you know what index to look for in the particular method you call, you do
not need to specify it here, because there is never a case where you call some
sorting method twice, each time with different index
2) you can call `desc()` in the sorting method itself, again, you do not
need to pass it here.
--
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]