> @@ -257,4 +265,21 @@ public String toString() {
> }
> }
>
> + public static Map<Integer, Integer> getPortRangesFromList(int... ports) {
> + Set<Integer> sortedPorts =
> ImmutableSortedSet.copyOf(Ints.asList(ports));
> +
> + RangeSet<Integer> ranges = TreeRangeSet.create();
> +
> + for (Integer port : sortedPorts) {
> + ranges.add(Range.closedOpen(port, port + 1));
> + }
> +
> + Map<Integer, Integer> portRanges = Maps.newHashMap();
> +
> + for (Range<Integer> r : ranges.asRanges()) {
> + portRanges.put(r.lowerEndpoint(), r.upperEndpoint() - 1);
> + }
I'm probably missing something here, but what is gained by the intermediate
creating of a `RangeSet`? Is it some kind of deduplication? I.e. is there no
way to easily go from the sorted input range straight to the `Map` result?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/35/files#r4736475