I have a list of ip objects that have their v4 address as a String. (ip is in decimal)
Now I want to sort this list in ascending order with the ip parts as search keys.
This was my first approach. It works but it needs four functions to return each part of the ip.
Comparator<IP> ipComparator =
Comparator
.comparing(IP::getFirstPart)
.thenComparing(IP::getSecondPart)
.thenComparing(IP::getThirdPart)
.thenComparing(IP::getFourthPart);
I would like to do something like this
Comparator<IP> ipComparator =
Comparator
.comparing(IP::getPart(0))
.thenComparing(IP::getPart(1))
.thenComparing(IP::getPart(2))
.thenComparing(IP::getPart(3));
What is the easiest way to implement this without defining a function to return each part of the ip?