@Test public static void testEqualToAny() { Assert.assertTrue(StringPredicates.equalToAny(ImmutableSet.of("1", "2")).apply("2")); Assert.assertFalse(StringPredicates.equalToAny(ImmutableSet.of("1", "2")).apply("3")); }
protected List<Location> findSubLocations(Location loc) { if (!loc.hasExtension(AvailabilityZoneExtension.class)) { throw new IllegalStateException("Availability zone extension not supported for location " + loc); } AvailabilityZoneExtension zoneExtension = loc.getExtension(AvailabilityZoneExtension.class); Collection<String> zoneNames = getConfig(AVAILABILITY_ZONE_NAMES); Integer numZones = getConfig(NUM_AVAILABILITY_ZONES); List<Location> subLocations; if (zoneNames == null || zoneNames.isEmpty()) { if (numZones != null) { subLocations = zoneExtension.getSubLocations(numZones); checkArgument(numZones > 0, "numZones must be greater than zero: %s", numZones); if (numZones > subLocations.size()) { throw new IllegalStateException("Number of required zones (" + numZones + ") not satisfied in " + loc + "; only " + subLocations.size() + " available: " + subLocations); } } else { subLocations = zoneExtension.getAllSubLocations(); } } else { // TODO check that these are valid region / availabilityZones? subLocations = zoneExtension.getSubLocationsByName(StringPredicates.equalToAny(zoneNames), zoneNames.size()); if (zoneNames.size() > subLocations.size()) { throw new IllegalStateException("Number of required zones (" + zoneNames.size() + " - " + zoneNames + ") not satisfied in " + loc + "; only " + subLocations.size() + " available: " + subLocations); } } LOG.info("Returning {} sub-locations: {}", subLocations.size(), Iterables.toString(subLocations)); return subLocations; }
throw new IllegalStateException(getEntity()+" is no longer managed; cannot create script to run here ("+phase+")"); if (!Iterables.all(flags.keySet(), StringPredicates.equalToAny(VALID_FLAGS))) { throw new IllegalArgumentException("Invalid flags passed: " + flags);