private static boolean match( final Artifact artifact, Iterable< String > artifactQualifiers ) { return from( artifactQualifiers ) .filter( MUST_NOT_BE_BLANK ) .anyMatch( new Predicate< String >() { @Override public boolean apply( String artifactQualifier ) { return match( artifact, artifactQualifier ); } } ); }
public void testAnyMatch() { ArrayList<String> list = Lists.newArrayList(); FluentIterable<String> iterable = FluentIterable.<String>from(list); Predicate<String> predicate = Predicates.equalTo("pants"); assertFalse(iterable.anyMatch(predicate)); list.add("cool"); assertFalse(iterable.anyMatch(predicate)); list.add("pants"); assertTrue(iterable.anyMatch(predicate)); }
public final boolean hasHeader(final HttpResponse httpResponse, final String name) { return from(httpResponse.getHeaders().entrySet()).anyMatch(isForHeaderName(name)); } }
@Override public final boolean match(final Request request) { Optional<T> extractContent = extractor.extract(request); if (!extractContent.isPresent()) { return false; } T target = extractContent.get(); if (target instanceof String) { return predicate.apply((String) target); } if (target instanceof String[]) { String[] contents = (String[]) target; return from(newArrayList(contents)).filter(notNull()).anyMatch(predicate); } if (target instanceof MessageContent) { MessageContent actualTarget = (MessageContent) target; return predicate.apply(actualTarget.toString()); } return false; }
private boolean isInBlackList(final String url, final String referer, List<String> blacklist) { return from(blacklist).anyMatch(new Predicate<String>() { @Override public boolean apply(String regex) { final Pattern pattern = Pattern.compile(regex); return pattern.matcher(url).matches() || (!StringUtils.isBlank(referer) && pattern.matcher(referer).matches()); } }); }
private boolean containsStack(Method method) { if (method == null) { return false; } List<Class<?>> parameterTypes = asList(method.getParameterTypes()); return FluentIterable.from(parameterTypes).anyMatch(hasStack()); }
public boolean apply(Invokable<?, ?> input) { return FluentIterable.from(Arrays.asList(input.getAnnotations())) .transform(new Function<Annotation, Class<? extends Annotation>>() { public Class<? extends Annotation> apply(Annotation input) { return input.annotationType(); } }).anyMatch(in(markers)); } };
private boolean projectNameAlreadyExistsInWorkspace(final String projectName) { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); return FluentIterable.from(Arrays.asList(projects)).anyMatch(new Predicate<IProject>() { @Override public boolean apply(IProject project) { return projectName.equals(project.getName()); } }); } };
@Test(dependsOnMethods = "testCreateRecord") public void testListResourceRecordsByName() { FluentIterable<ResourceRecord> byName = api(zoneName).listByName(mx.getName()).transform(toRecord); assertTrue(byName.anyMatch(equalTo(mx))); }
@Test public void testListTagKeys() { PagedIterable<TagKey> response = api().listTagKeys(); // assert that the created tag is present in the list of tag keys. assertTrue(FluentIterable.from(response.concat().toList()).anyMatch(new Predicate<TagKey>() { @Override public boolean apply(TagKey input) { return input.id().equals(tagKeyId); } })); }
@Test(dependsOnMethods = "testUpdateRecord") public void testDeleteRecord() { api(zoneName).delete(guid); assertFalse(listRRs().anyMatch(equalTo(mx))); }
@Test(dependsOnMethods = "testCloneServerToMakeCustomerImage") public void testListCustomerImages() { FluentIterable<CustomerImage> customerImages = api.getServerImageApi().listCustomerImages().concat(); assertNotNull(customerImages); assertTrue(customerImages.anyMatch(new Predicate<CustomerImage>() { @Override public boolean apply(CustomerImage input) { return input.id().equals(cloneImageId); } })); }
@Test(dependsOnMethods = "testCreateRecord") public void testListResourceRecordsByNameAndType() { FluentIterable<ResourceRecord> byNameAndType = api(zoneName).listByNameAndType(mx.getName(), mx.getType()) .transform(toRecord); assertTrue(byNameAndType.anyMatch(equalTo(mx))); }
@Test public void testCreateRecord() { guid = api(zoneName).create(mx); getAnonymousLogger().info("created record: " + guid); try { api(zoneName).create(mx); fail(); } catch (ResourceAlreadyExistsException e) { } assertTrue(listRRs().anyMatch(equalTo(mx))); }
@Test(dependsOnMethods = "testListTags") public void testRemoveTagFromServer() { api.getTagApi().removeTags(serverId, "SERVER", Collections.singletonList(tagKeyId)); assertFalse(FluentIterable.from(api.getTagApi().listTags().concat().toList()).anyMatch(new Predicate<Tag>() { @Override public boolean apply(Tag input) { return input.tagKeyId().equals(tagKeyId); } })); }
@Test(dependsOnMethods = { "testListResourceRecordsByName", "testListResourceRecordsByNameAndType" }) public void testUpdateRecord() { mx = mx.toBuilder().ttl(3600).build(); api(zoneName).update(guid, mx); assertTrue(listRRs().anyMatch(equalTo(mx))); }
@Test public void testListZonesByAccount() { FluentIterable<Zone> response = api().listByAccount(account.getId()); for (Zone zone : response) { checkZone(zone); } if (response.anyMatch(typeEqualTo(PRIMARY))) { assertEquals(api().listByAccountAndType(account.getId(), PRIMARY).toSet(), response .filter(typeEqualTo(PRIMARY)).toSet()); } }
@Test(dependsOnMethods = "testUpdateRecord") public void testDeleteRecord() { api(zoneName).deleteRecord(aRecord2); assertTrue(listRRs(aPoolId).anyMatch( equalTo(rrBuilder().name(dname).type(1).ttl(0).rdata("1.1.1.1").build()))); assertFalse(listRRs(aPoolId).anyMatch( equalTo(rrBuilder().name(dname).type(1).ttl(1).rdata("3.4.5.6").build()))); }
@Test(dependsOnMethods = "addARecordToPool") public void testUpdateRecord() { api(zoneName).updateRecordWithAddressAndTTL(aPoolId, aRecord1, "1.1.1.1", 0); assertTrue(listRRs(aPoolId).anyMatch( equalTo(rrBuilder().name(dname).type(1).ttl(0).rdata("1.1.1.1").build()))); }