@VisibleForTesting static List<String> getIpAddressWebsites() { String file = new ResourceUtils(LocalhostExternalIpLoader.class) .getResourceAsString("classpath://org/apache/brooklyn/location/geo/external-ip-address-resolvers.txt"); Iterable<String> lines = Splitter.on('\n') .omitEmptyStrings() .trimResults() .split(file); List<String> urls = Lists.newArrayList(Iterables.filter(lines, Predicates.not(StringPredicates.startsWith("#")))); Collections.shuffle(urls); return urls; }
/** * @since 0.9.0 */ public static Predicate<ConfigKey<?>> nameStartsWith(final String prefix) { return nameSatisfies(StringPredicates.startsWith(prefix)); }
/** true if the object *is* a {@link CharSequence} starting with the given prefix */ public static Predicate<Object> isStringStartingWith(final String prefix) { return Predicates.<Object>and(Predicates.instanceOf(CharSequence.class), Predicates.compose(startsWith(prefix), StringFunctions.toStringFunction())); }
/** * Gets all properties that start with the given {@code <firstPrefix>.<secondPrefix>}, stripping off * the {@code firstPrefix} in the returned map. */ protected Map<String, Object> getMatchingConcatenatedPrefixesPropertiesFirstPrefixRemoved(String firstPrefix, String secondPrefix, Map<String, ?> properties) { BrooklynProperties filteredProperties = ConfigUtils.filterForPrefixAndStrip(properties, firstPrefix); return ConfigUtils.filterFor(filteredProperties, StringPredicates.startsWith(secondPrefix)).asMapWithStringKeys(); }
@Test public static void testStartsWith() { Assert.assertTrue(StringPredicates.startsWith("t").apply("test")); Assert.assertFalse(StringPredicates.startsWith("v").apply("test")); Assert.assertTrue(StringPredicates.isStringStartingWith("t").apply("test")); Assert.assertFalse(StringPredicates.isStringStartingWith("t").apply(true)); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { managementContext = LocalManagementContextForTests.newInstance(); brooklynProperties = managementContext.getBrooklynProperties(); defaultNamePredicate = StringPredicates.startsWith(FixedListMachineProvisioningLocation.class.getSimpleName()); }
public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); Set<ConfigKey<?>> keys = properties.findKeys(ConfigPredicates.nameSatisfies(StringPredicates.startsWith(prefix))); for (ConfigKey<?> key : keys) { result.put(key, properties.getConfig(key)); } return result; }
@Test public void testListAttributeWhenReadyFromMultipleEntitiesWithLocalReadinessPredicate() throws Exception { final Task<List<String>> t = submit(DependentConfiguration.builder() .attributeWhenReadyFromMultiple(ImmutableList.of(entity, entity2), TestEntity.NAME, StringPredicates.startsWith("myval")) .build()); entity.sensors().set(TestEntity.NAME, "wrongval"); entity2.sensors().set(TestEntity.NAME, "wrongval2"); assertNotDoneContinually(t); entity.sensors().set(TestEntity.NAME, "myval"); assertNotDoneContinually(t); entity2.sensors().set(TestEntity.NAME, "myval2"); assertEquals(ImmutableSet.copyOf(assertDoneEventually(t)), ImmutableSet.of("myval", "myval2")); }
String id = Strings.getFirstWord(line); Optional<Entity> container = Iterables.tryFind(getDockerContainerCluster().getMembers(), Predicates.compose(StringPredicates.startsWith(id), EntityFunctions.attribute(DockerContainer.DOCKER_CONTAINER_ID))); if (container.isPresent()) continue;
Map<String, Object> sshToolClassProperties = Maps.filterKeys(setup.getAllConfig(), StringPredicates.startsWith(SshMachineLocation.SSH_TOOL_CLASS_PROPERTIES_PREFIX)); sshConfig.putAll(sshToolClassProperties);