Java Code Examples for com.google.common.collect.Iterables#any()

The following examples show how to use com.google.common.collect.Iterables#any() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dremio-oss   File: DependencyManager.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source Project: presto   File: TestEqualityInference.java    License: Apache License 2.0 5 votes vote down vote up
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));
    };
}
 
Example 3
Source Project: emodb   File: DatabusClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 4
@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);
}
 
Example 5
Source Project: emodb   File: BlobStoreClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 6
Source Project: Kylin   File: ProjectInstance.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 7
Source Project: emodb   File: DataStoreClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 8
public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
	for (DiagnosticPredicate predicate : predicates)
		if (Iterables.any(getAllDiagnostics(), predicate))
			return this;
	fail("predicate not found");
	return this;
}
 
Example 9
/**
 * 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()));
}
 
Example 10
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());
        }
    });
}
 
Example 11
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;
}
 
Example 12
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);
                }
            });
}
 
Example 13
Source Project: rocketmq   File: BrokerOuterAPITest.java    License: Apache License 2.0 5 votes vote down vote up
@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);

}
 
Example 14
public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
	for (DiagnosticPredicate predicate : predicates)
		if (Iterables.any(getAllDiagnostics(), predicate))
			return this;
	fail("predicate not found");
	return this;
}
 
Example 15
Source Project: immutables   File: ValueType.java    License: Apache License 2.0 5 votes vote down vote up
private boolean useCollectionUtility(Predicate<ValueAttribute> predicate) {
  for (ValueType n : nested) {
    if (Iterables.any(n.getSettableAttributes(), predicate)) {
      return true;
    }
  }
  return Iterables.any(getSettableAttributes(), predicate);
}
 
Example 16
@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;
}
 
Example 17
Source Project: statecharts   File: SCTBuilder.java    License: Eclipse Public License 1.0 4 votes vote down vote up
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));
}
 
Example 18
@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;
}
 
Example 19
@Override
public boolean isEmpty() {
    return Iterables.any(inventory, Predicates.notNull());
}
 
Example 20
@Override
public Collection<IDataProviderDescriptor> getDescriptors(@NonNull ITmfTrace trace) {
    Collection<ITmfTrace> traces = TmfTraceManager.getTraceSet(trace);
    return Iterables.any(traces, PREDICATE) ? Collections.singletonList(DESCRIPTOR) : Collections.emptyList();
}