The original comment was eaten by a force push of mine, I think, so
commenting here - yes, deduplication. As a result, we'll go from [5, 6, 7,
10, 11, 20] to [[5, 7], [10, 11], [20, 20]] - so we'd save at least one
call to authorizeSecurityGroupIngress or equivalent in this case (well,
actually, if we're using aws-ec2, it doesn't really matter much anyway, but
generally? it does.).

A.

On Mon, Jun 17, 2013 at 3:08 PM, Andrew Phillips
<[email protected]>wrote:

> > @@ -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
>

Reply via email to