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

The following examples show how to use com.google.common.collect.Iterables#any() . 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 File: DependencyManager.java    From dremio-oss with 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 File: TestEqualityInference.java    From presto with 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 File: ValueType.java    From immutables with 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 4
Source File: AssertableDiagnostics.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
	for (DiagnosticPredicate predicate : predicates)
		if (Iterables.any(getAllDiagnostics(), predicate))
			return this;
	fail("predicate not found");
	return this;
}
 
Example 5
Source File: BrokerOuterAPITest.java    From rocketmq with 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 6
Source File: AggregateTestResultsProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 7
Source File: TmfTreeXYCompositeDataProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
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 8
Source File: CompanyUpdateBuilder.java    From intercom-java with Apache License 2.0 5 votes vote down vote up
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 9
Source File: AppEngineProjectElement.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: AssertableDiagnostics.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
	for (DiagnosticPredicate predicate : predicates)
		if (Iterables.any(getAllDiagnostics(), predicate))
			return this;
	fail("predicate not found");
	return this;
}
 
Example 11
Source File: DataStoreClientFactory.java    From emodb with 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 12
Source File: ProjectInstance.java    From Kylin with 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 13
Source File: BlobStoreClientFactory.java    From emodb with 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 14
Source File: PullFileLoader.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: DatabusClientFactory.java    From emodb with 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 16
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: InventoryWrapper.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isEmpty() {
    return Iterables.any(inventory, Predicates.notNull());
}
 
Example 18
Source File: KernelMemoryDataProviderFactory.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Collection<IDataProviderDescriptor> getDescriptors(@NonNull ITmfTrace trace) {
    Collection<ITmfTrace> traces = TmfTraceManager.getTraceSet(trace);
    return Iterables.any(traces, PREDICATE) ? Collections.singletonList(DESCRIPTOR) : Collections.emptyList();
}
 
Example 19
Source File: SCTBuilder.java    From statecharts with 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 20
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
@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;
}