ctubbsii commented on a change in pull request #2551:
URL: https://github.com/apache/accumulo/pull/2551#discussion_r822907068
##########
File path: core/src/main/java/org/apache/accumulo/core/util/HostAndPort.java
##########
@@ -281,4 +282,16 @@ public int getPortOrDefault(int defaultPort) {
return hasPort() ? port : defaultPort;
}
+ /**
+ * HostAndPort must implement compareTo. As this is a seldom used utility,
compareTo simply treats
+ * HostAndPort values as Strings.
+ */
+ @Override
+ public int compareTo(HostAndPort other) {
+ return Comparator
+ .nullsFirst(
+ Comparator.comparing(HostAndPort::getHost).thenComparingInt(h ->
h.getPortOrDefault(0)))
Review comment:
Oh, and I forgot to mention. Rather than constructing a new comparator
each time, you can save the comparator in a static private final field, and
just call it in the compareTo method.
--
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]