本文整理了Java中java.util.stream.Stream.allMatch()
方法的一些代码示例,展示了Stream.allMatch()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.allMatch()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:allMatch
[英]Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the stream is empty then true is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
[中]返回此流的所有元素是否与提供的谓词匹配。如果不需要确定结果,则不能对所有元素的谓词求值。如果流为空,则返回true,并且不计算谓词。
这是一个short-circuiting terminal operation。
代码示例来源:origin: prestodb/presto
private static boolean allBlocksHaveRealAddress(List<InternalHiveBlock> blocks)
{
return blocks.stream()
.map(InternalHiveBlock::getAddresses)
.allMatch(InternalHiveSplitFactory::hasRealAddress);
}
代码示例来源:origin: apache/storm
/**
* Convenience method for data.stream.allMatch(pred)
*/
public static <T> boolean isEvery(Collection<T> data, Predicate<T> pred) {
return data.stream().allMatch(pred);
}
代码示例来源:origin: prestodb/presto
private void printPlanNodesStatsAndCost(int indent, PlanNode... nodes)
{
if (stream(nodes).allMatch(this::isPlanNodeStatsAndCostsUnknown)) {
return;
}
print(indent, "Cost: %s", stream(nodes).map(this::formatPlanNodeStatsAndCost).collect(joining("/")));
}
代码示例来源:origin: prestodb/presto
@Override
public Type createType(TypeManager typeManager, List<TypeParameter> parameters)
{
checkArgument(parameters.size() >= 1, "Function type must have at least one parameter, got %s", parameters);
checkArgument(
parameters.stream().allMatch(parameter -> parameter.getKind() == ParameterKind.TYPE),
"Expected only types as a parameters, got %s",
parameters);
List<Type> types = parameters.stream().map(TypeParameter::getType).collect(toList());
return new FunctionType(types.subList(0, types.size() - 1), types.get(types.size() - 1));
}
}
代码示例来源:origin: prestodb/presto
private static void verifyFileHasColumnNames(List<String> physicalColumnNames, Path path)
{
if (!physicalColumnNames.isEmpty() && physicalColumnNames.stream().allMatch(physicalColumnName -> DEFAULT_HIVE_COLUMN_NAME_PATTERN.matcher(physicalColumnName).matches())) {
throw new PrestoException(
HIVE_FILE_MISSING_COLUMN_NAMES,
"ORC file does not contain column names in the footer: " + path);
}
}
代码示例来源:origin: prestodb/presto
private static boolean allDistinctAggregates(AggregationNode aggregation)
{
return aggregation.getAggregations()
.values().stream()
.map(Aggregation::getCall)
.allMatch(FunctionCall::isDistinct);
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldBeThreadSafe() {
// When:
final List<CompletableFuture<Void>> futures = IntStream.range(1, 11).parallel()
.mapToObj(idx -> {
final CompletableFuture<Void> f = futureStore.getFutureForSequenceNumber(idx);
if (idx % 10 == 0) {
futureStore.completeFuturesUpToAndIncludingSequenceNumber(idx);
}
return f;
})
.collect(Collectors.toList());
// Then:
assertThat(futures.stream().allMatch(CompletableFuture::isDone), is(true));
}
代码示例来源:origin: apache/storm
@Override
public boolean isReady(Set<String> nodeIds) {
if (exceedsMaxTimeOut()) {
Set<String> tmp = nodeIds.stream().filter(id -> !this.reportedIds.contains(id)).collect(toSet());
LOG.warn("Failed to recover heartbeats for nodes: {} with timeout {}s", tmp, NODE_MAX_TIMEOUT_SECS);
return true;
}
return nodeIds.stream().allMatch(id -> this.reportedIds.contains(id));
}
代码示例来源:origin: MovingBlocks/Terasology
@SafeVarargs
@Override
public final Iterable<EntityRef> getEntitiesWith(Class<? extends Component>... componentClasses) {
return () -> entityStore.keySet().stream()
//Keep entities which have all of the required components
.filter(id -> Arrays.stream(componentClasses)
.allMatch(component -> componentStore.get(id, component) != null))
.map(id -> getEntity(id))
.iterator();
}
代码示例来源:origin: wildfly/wildfly
public boolean hasAllResponses() {
lock.lock();
try {
return responses.isEmpty() || responses.entrySet().stream().allMatch(entry -> entry.getValue() != null);
}
finally {
lock.unlock();
}
}
代码示例来源:origin: prestodb/presto
private ComputedStatistics(
List<String> groupingColumns,
List<Block> groupingValues,
Map<TableStatisticType, Block> tableStatistics,
Map<ColumnStatisticMetadata, Block> columnStatistics)
{
this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
}
this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
}
this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
}
}
代码示例来源:origin: google/error-prone
private static Predicate<String> areAllReturnStatementsAssignable(
ImmutableSet<ClassType> returnStatementsTypes) {
return s ->
returnStatementsTypes.stream()
.map(MutableMethodReturnType::getImmutableSuperTypesForClassType)
.allMatch(c -> c.contains(s));
}
代码示例来源:origin: prestodb/presto
private static List<ColumnStatistics> toFileStats(List<List<ColumnStatistics>> stripes)
{
if (stripes.isEmpty()) {
return ImmutableList.of();
}
int columnCount = stripes.get(0).size();
checkArgument(stripes.stream().allMatch(stripe -> columnCount == stripe.size()));
ImmutableList.Builder<ColumnStatistics> fileStats = ImmutableList.builder();
for (int i = 0; i < columnCount; i++) {
int column = i;
fileStats.add(ColumnStatistics.mergeColumnStatistics(stripes.stream()
.map(stripe -> stripe.get(column))
.collect(toList())));
}
return fileStats.build();
}
代码示例来源:origin: prestodb/presto
private static boolean isTypeWithLiteralParameters(TypeSignature typeSignature)
{
return typeSignature.getParameters().stream()
.map(TypeSignatureParameter::getKind)
.allMatch(kind -> kind == ParameterKind.LONG || kind == ParameterKind.VARIABLE);
}
代码示例来源:origin: prestodb/presto
@JsonProperty
public boolean isFinalQueryInfo()
{
return state.isDone() && getAllStages(outputStage).stream().allMatch(StageInfo::isFinalStageInfo);
}
代码示例来源:origin: joel-costigliola/assertj-core
@SafeVarargs
private final SELF satisfiesAnyOfAssertionsGroups(Consumer<ACTUAL>... assertionsGroups) throws AssertionError {
checkArgument(stream(assertionsGroups).allMatch(assertions -> assertions != null), "No assertions group should be null");
if (stream(assertionsGroups).anyMatch(this::satisfiesAssertions)) return myself;
// none of the assertions group was met! let's report all the errors
List<AssertionError> assertionErrors = stream(assertionsGroups).map(this::catchAssertionError).collect(toList());
throw multipleAssertionsError(assertionErrors);
}
代码示例来源:origin: prestodb/presto
public boolean isDecomposable(FunctionRegistry functionRegistry)
{
boolean hasOrderBy = getAggregations().values().stream()
.map(Aggregation::getCall)
.map(FunctionCall::getOrderBy)
.anyMatch(Optional::isPresent);
boolean hasDistinct = getAggregations().values().stream()
.map(Aggregation::getCall)
.anyMatch(FunctionCall::isDistinct);
boolean decomposableFunctions = getAggregations().values().stream()
.map(Aggregation::getSignature)
.map(functionRegistry::getAggregateFunctionImplementation)
.allMatch(InternalAggregationFunction::isDecomposable);
return !hasOrderBy && !hasDistinct && decomposableFunctions;
}
代码示例来源:origin: neo4j/neo4j
public static boolean hasCompatibleCapabilities( RecordFormats one, RecordFormats other, CapabilityType type )
{
Set<Capability> myFormatCapabilities = Stream.of( one.capabilities() )
.filter( capability -> capability.isType( type ) ).collect( toSet() );
Set<Capability> otherFormatCapabilities = Stream.of( other.capabilities() )
.filter( capability -> capability.isType( type ) ).collect( toSet() );
if ( myFormatCapabilities.equals( otherFormatCapabilities ) )
{
// If they have the same capabilities then of course they are compatible
return true;
}
boolean capabilitiesNotRemoved = otherFormatCapabilities.containsAll( myFormatCapabilities );
otherFormatCapabilities.removeAll( myFormatCapabilities );
boolean allAddedAreAdditive = otherFormatCapabilities.stream().allMatch( Capability::isAdditive );
// Even if capabilities of the two aren't the same then there's a special case where if the additional
// capabilities of the other format are all additive then they are also compatible because no data
// in the existing store needs to be migrated.
return capabilitiesNotRemoved && allAddedAreAdditive;
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public boolean isConstant() {
return map.values().stream().allMatch(Expression::isConstant);
}
代码示例来源:origin: apache/flink
private boolean checkForCustomFieldMapping(DescriptorProperties descriptorProperties, TableSchema schema) {
final Map<String, String> fieldMapping = SchemaValidator.deriveFieldMapping(
descriptorProperties,
Optional.of(schema.toRowType())); // until FLINK-9870 is fixed we assume that the table schema is the output type
return fieldMapping.size() != schema.getFieldNames().length ||
!fieldMapping.entrySet().stream().allMatch(mapping -> mapping.getKey().equals(mapping.getValue()));
}
内容来源于网络,如有侵权,请联系作者删除!