下面列出了com.google.common.collect.Iterables#any ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void setDependencies(final ReflectionId reflectionId, ExtractedDependencies extracted) throws DependencyException {
Preconditions.checkState(!extracted.isEmpty(), "expected non empty dependencies");
Set<DependencyEntry> dependencies = extracted.getPlanDependencies();
if (Iterables.isEmpty(dependencies)) {
// no plan dependencies found, use decision dependencies instead
graph.setDependencies(reflectionId, extracted.getDecisionDependencies());
return;
}
// if P > R1 > R2 and R2 is either FAILED or DEPRECATED we should exclude it from the dependencies and include
// all datasets instead. We do this to avoid never refreshing R2 again if R1 is never refreshed
// Note that even though delete(R1) will also update R2 dependencies, it may not be enough if R2 was refreshing
// while the update happens as setDependencies(R2, ...) would overwrite the update, that's why we include all the datasets
if (Iterables.any(dependencies, isDeletedReflection)) {
// filter out deleted reflections, and include all dataset dependencies
dependencies = FluentIterable.from(dependencies)
.filter(not(isDeletedReflection))
.append(extracted.getDecisionDependencies())
.toSet();
}
graph.setDependencies(reflectionId, dependencies);
}
private static Predicate<Expression> matchesStraddlingScope(final Predicate<Symbol> symbolScope)
{
return expression -> {
Set<Symbol> symbols = SymbolsExtractor.extractUnique(expression);
return Iterables.any(symbols, symbolScope) && Iterables.any(symbols, not(symbolScope));
};
}
@Override
public boolean isRetriableException(Exception e) {
return super.isRetriableException(e) ||
(e instanceof UniformInterfaceException &&
((UniformInterfaceException) e).getResponse().getStatus() >= 500) ||
Iterables.any(Throwables.getCausalChain(e), Predicates.instanceOf(ClientHandlerException.class));
}
@Override
public boolean accept(final Path path) {
Predicate<String> predicate = new Predicate<String>() {
@Override
public boolean apply(String input) {
return path.getName().toLowerCase().endsWith(input);
}
};
return Iterables.any(this.extensions, predicate);
}
@Override
public boolean isRetriableException(Exception e) {
return super.isRetriableException(e) ||
(e instanceof UniformInterfaceException &&
((UniformInterfaceException) e).getResponse().getStatus() >= 500) ||
Iterables.any(Throwables.getCausalChain(e), Predicates.instanceOf(ClientHandlerException.class));
}
public boolean containsRealization(final RealizationType type, final String realization) {
return Iterables.any(this.realizationEntries, new Predicate<RealizationEntry>() {
@Override
public boolean apply(RealizationEntry input) {
return input.getType() == type && input.getRealization().equalsIgnoreCase(realization);
}
});
}
@Override
public boolean isRetriableException(Exception e) {
return super.isRetriableException(e) ||
(e instanceof UniformInterfaceException &&
((UniformInterfaceException) e).getResponse().getStatus() >= 500) ||
Iterables.any(Throwables.getCausalChain(e), Predicates.instanceOf(ClientHandlerException.class));
}
public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
for (DiagnosticPredicate predicate : predicates)
if (Iterables.any(getAllDiagnostics(), predicate))
return this;
fail("predicate not found");
return this;
}
/**
* Return {@code true} if the list of changed files includes an App Engine descriptor. This file
* may not necessarily be the resolved descriptor.
*/
public static boolean hasAppEngineDescriptor(Collection<IFile> changedFiles) {
Preconditions.checkNotNull(changedFiles);
return Iterables.any(
changedFiles,
file -> file != null && APPENGINE_DESCRIPTOR_FILENAMES.contains(file.getName()));
}
private static boolean isCompanyInList(final Company company, CompanyCollection companyCollection) {
if (companyCollection == null) {
return false;
}
return Iterables.any(companyCollection.getPage(), new Predicate<Company>() {
@Override
public boolean apply(Company e) {
return Objects.equal(company.getCompanyID(), e.getCompanyID())
|| Objects.equal(company.getId(), e.getId());
}
});
}
private static @Nullable String handleFailedStatus(Collection<TmfModelResponse<ITmfXyModel>> responses) {
if (Iterables.any(responses, response -> response.getStatus() == ITmfResponse.Status.FAILED)) {
// All requests have failed, return a concatenation of their errors
return responses.stream().map(TmfModelResponse::getStatusMessage)
.collect(Collectors.joining("\n")); //$NON-NLS-1$
}
// At least one is good, return null
return null;
}
public boolean hasOutput(long id, final TestOutputEvent.Destination destination) {
return Iterables.any(
classOutputProviders.get(id),
new Predicate<DelegateProvider>() {
public boolean apply(DelegateProvider delegateProvider) {
return delegateProvider.provider.hasOutput(delegateProvider.id, destination);
}
});
}
@Test
public void test_needRegister_timeout() throws Exception {
init();
brokerOuterAPI.start();
TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
when(nettyRemotingClient.getNameServerAddressList()).thenReturn(Lists.asList(nameserver1, nameserver2, new String[] {nameserver3}));
when(nettyRemotingClient.invokeSync(anyString(), any(RemotingCommand.class), anyLong())).thenAnswer(new Answer<RemotingCommand>() {
@Override
public RemotingCommand answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArgument(0) == nameserver1) {
return buildResponse(Boolean.TRUE);
} else if (invocation.getArgument(0) == nameserver2) {
return buildResponse(Boolean.FALSE);
} else if (invocation.getArgument(0) == nameserver3) {
TimeUnit.MILLISECONDS.sleep(timeOut + 20);
return buildResponse(Boolean.TRUE);
}
return buildResponse(Boolean.TRUE);
}
});
List<Boolean> booleanList = brokerOuterAPI.needRegister(clusterName, brokerAddr, brokerName, brokerId, topicConfigSerializeWrapper, timeOut);
assertEquals(2, booleanList.size());
boolean success = Iterables.any(booleanList,
new Predicate<Boolean>() {
public boolean apply(Boolean input) {
return input ? true : false;
}
});
assertEquals(true, success);
}
public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
for (DiagnosticPredicate predicate : predicates)
if (Iterables.any(getAllDiagnostics(), predicate))
return this;
fail("predicate not found");
return this;
}
private boolean useCollectionUtility(Predicate<ValueAttribute> predicate) {
for (ValueType n : nested) {
if (Iterables.any(n.getSettableAttributes(), predicate)) {
return true;
}
}
return Iterables.any(getSettableAttributes(), predicate);
}
@Override
public Void visitAnnotation(AnnotationTree node, Void unused) {
sync(node);
if (visitSingleMemberAnnotation(node)) {
return null;
}
builder.open(ZERO);
token("@");
scan(node.getAnnotationType(), null);
if (!node.getArguments().isEmpty()) {
builder.open(plusFour);
token("(");
builder.breakOp();
boolean first = true;
// Format the member value pairs one-per-line if any of them are
// initialized with arrays.
boolean hasArrayInitializer =
Iterables.any(node.getArguments(), JavaInputAstVisitor::isArrayValue);
for (ExpressionTree argument : node.getArguments()) {
if (!first) {
token(",");
if (hasArrayInitializer) {
builder.forcedBreak();
} else {
builder.breakOp(" ");
}
}
if (argument instanceof AssignmentTree) {
visitAnnotationArgument((AssignmentTree) argument);
} else {
scan(argument, null);
}
first = false;
}
token(")");
builder.close();
builder.close();
return null;
} else if (builder.peekToken().equals(Optional.of("("))) {
token("(");
token(")");
}
builder.close();
return null;
}
private boolean isGenmodelForStatechart(IResource genmodelResource, final Statechart statechart) {
GeneratorModel genModel = loadFromResource(genmodelResource);
return genModel != null && !genModel.getEntries().isEmpty()
&& Iterables.any(genModel.getEntries(), new ElementRefGenerator(statechart));
}
@Override
public Void visitAnnotation(AnnotationTree node, Void unused) {
sync(node);
if (visitSingleMemberAnnotation(node)) {
return null;
}
builder.open(ZERO);
token("@");
scan(node.getAnnotationType(), null);
if (!node.getArguments().isEmpty()) {
builder.open(plusTwo);
token("(");
builder.breakOp();
boolean first = true;
// Format the member value pairs one-per-line if any of them are
// initialized with arrays.
boolean hasArrayInitializer = Iterables.any(node.getArguments(), IS_ARRAY_VALUE);
for (ExpressionTree argument : node.getArguments()) {
if (!first) {
token(",");
if (hasArrayInitializer) {
builder.forcedBreak();
} else {
builder.breakOp(" ");
}
}
if (argument instanceof AssignmentTree) {
visitAnnotationArgument((AssignmentTree) argument);
} else {
scan(argument, null);
}
first = false;
}
builder.breakOp(UNIFIED, "", minusTwo, Optional.<BreakTag>absent());
builder.close();
token(")", plusTwo);
builder.close();
return null;
} else if (builder.peekToken().equals(Optional.of("("))) {
token("(");
token(")");
}
builder.close();
return null;
}
@Override
public boolean isEmpty() {
return Iterables.any(inventory, Predicates.notNull());
}
@Override
public Collection<IDataProviderDescriptor> getDescriptors(@NonNull ITmfTrace trace) {
Collection<ITmfTrace> traces = TmfTraceManager.getTraceSet(trace);
return Iterables.any(traces, PREDICATE) ? Collections.singletonList(DESCRIPTOR) : Collections.emptyList();
}