@Override public List<Location> getListOfLocationsManaged(Object l) { if (l==null) l = Collections.emptyList(); if (l instanceof String) l = JavaStringEscapes.unwrapJsonishListIfPossible((String)l); if (l instanceof Iterable) return getFromIterableListOfLocationsManaged((Iterable<?>)l); throw new IllegalArgumentException("Location list must be supplied as a collection or a string, not "+ JavaClassNames.simpleClassName(l)+"/"+l); }
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); }
@SuppressWarnings("unchecked") @Test public void testRegistryCommaResolution() throws NoMachinesAvailableException { List<Location> l; l = getLocationResolver().getListOfLocationsManaged(JavaStringEscapes.unwrapJsonishListIfPossible("localhost,localhost,localhost")); assertEquals(l.size(), 3, "l="+l); assertTrue(l.get(0) instanceof LocalhostMachineProvisioningLocation, "l="+l); assertTrue(l.get(1) instanceof LocalhostMachineProvisioningLocation, "l="+l); assertTrue(l.get(2) instanceof LocalhostMachineProvisioningLocation, "l="+l); // And check works if comma in brackets l = getLocationResolver().getListOfLocationsManaged(JavaStringEscapes.unwrapJsonishListIfPossible( "[ \"byon:(hosts=\\\"192.168.0.1\\\",user=bob)\", \"byon:(hosts=\\\"192.168.0.2\\\",user=bob2)\" ]")); assertEquals(l.size(), 2, "l="+l); assertTrue(l.get(0) instanceof FixedListMachineProvisioningLocation, "l="+l); assertTrue(l.get(1) instanceof FixedListMachineProvisioningLocation, "l="+l); assertEquals(((FixedListMachineProvisioningLocation<SshMachineLocation>)l.get(0)).obtain().getUser(), "bob"); assertEquals(((FixedListMachineProvisioningLocation<SshMachineLocation>)l.get(1)).obtain().getUser(), "bob2"); }
List<String> catalogsAdd = Strings.isBlank(catalogAdd) ? ImmutableList.<String>of() : JavaStringEscapes.unwrapJsonishListIfPossible(catalogAdd); CatalogInitialization catInit = new CatalogInitialization(catalogInitial, catalogReset, catalogsAdd, catalogForce); catInit.addPopulationCallback(new Function<CatalogInitialization,Void>() {
for (String targetSpec : JavaStringEscapes.unwrapJsonishListIfPossible((String)targetSpecs)) { targets.add(managementContext.getLocationRegistry().getLocationSpec(targetSpec, ImmutableMap.of()).get());
.ignoreWebErrors(startupContinueOnWebErrors) .ignoreAppErrors(!startupFailOnManagedAppsErrors) .locations(Strings.isBlank(locations) ? ImmutableList.<String>of() : JavaStringEscapes.unwrapJsonishListIfPossible(locations));
JavaStringEscapes.unwrapJsonishListIfPossible("\"hello\", \"world\"")); Assert.assertEquals(MutableList.of("hello"), JavaStringEscapes.unwrapJsonishListIfPossible("hello")); Assert.assertEquals(MutableList.of("hello", "world"), JavaStringEscapes.unwrapJsonishListIfPossible("hello, world")); Assert.assertEquals(MutableList.of("hello", "world"), JavaStringEscapes.unwrapJsonishListIfPossible("\"hello\", world")); Assert.assertEquals(MutableList.of("hello", "world"), JavaStringEscapes.unwrapJsonishListIfPossible("[ \"hello\", world ]")); JavaStringEscapes.unwrapJsonishListIfPossible("hello\", \"world\"")); Assert.assertEquals(MutableList.of(), JavaStringEscapes.unwrapJsonishListIfPossible(" ")); Assert.assertEquals(MutableList.of(""), JavaStringEscapes.unwrapJsonishListIfPossible("\"\"")); Assert.assertEquals(MutableList.of("x"), JavaStringEscapes.unwrapJsonishListIfPossible(",,x,")); Assert.assertEquals(MutableList.of("","x",""), JavaStringEscapes.unwrapJsonishListIfPossible("\"\",,x,\"\""));
@Override public Set<String> apply(final String input) { return MutableSet.copyOf(JavaStringEscapes.unwrapJsonishListIfPossible(input)).asUnmodifiable(); } });
@Override public List<String> apply(final String input) { return JavaStringEscapes.unwrapJsonishListIfPossible(input); } });