@Override public PortRange apply(Iterable x) { return fromIterable(x); } });
protected List<Integer> toIntPortList(Object v) { if (v == null) return ImmutableList.of(); PortRange portRange = PortRanges.fromIterable(ImmutableList.of(v)); return ImmutableList.copyOf(portRange); }
@Test public void testFromIterable() { PortRange r = PortRanges.fromIterable(ImmutableList.of(1234, 2345)); assertContents(r, 1234, 2345); }
public static PortRange fromIterable(Iterable<?> c) { List<PortRange> l = new ArrayList<PortRange>(); for (Object o: c) { if (o instanceof Integer) l.add(fromInteger((Integer)o)); else if (o instanceof String) for (String string : JavaStringEscapes.unwrapJsonishListIfPossible((String)o)) l.add(fromString(string)); else if (o instanceof Iterable) l.add(fromIterable((Iterable<?>)o)); else if (o instanceof int[]) l.add(fromIterable(Ints.asList((int[])o))); else if (o instanceof String[]) for (String string : (String[])o) l.add(fromString(string)); else if (o instanceof Object[]) for (Object object : (Object[])o) if (object instanceof Integer) l.add(fromInteger((Integer)object)); else if (object instanceof String) l.add(fromString((String)object)); else throw new IllegalArgumentException("'" + object + "' must be of type Integer or String"); else l.add(TypeCoercions.coerce(o, PortRange.class)); } return new AggregatePortRange(l); }