本文整理了Java中java.util.stream.Collectors.partitioningBy()
方法的一些代码示例,展示了Collectors.partitioningBy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collectors.partitioningBy()
方法的具体详情如下:
包路径:java.util.stream.Collectors
类名称:Collectors
方法名:partitioningBy
暂无
代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises
public Map<Boolean, List<Artist>> bandsAndSoloRef(Stream<Artist> artists) {
return artists.collect(partitioningBy(Artist::isSolo));
}
// END BANDS_AND_SOLO_REF
代码示例来源:origin: rest-assured/rest-assured
private static void applyConfigurersAndFilter(Object[] configurersOrExchangeFilterFunctions,
WebTestClient.Builder builder) {
Map<Boolean, List<Object>> partitionedByConfigurer = Arrays.stream(configurersOrExchangeFilterFunctions)
.collect(partitioningBy(WebTestClientConfigurer.class::isInstance));
partitionedByConfigurer.get(true).stream().map(WebTestClientConfigurer.class::cast)
.forEach(builder::apply);
partitionedByConfigurer.get(false).stream()
.filter(ExchangeFilterFunction.class::isInstance)
.map(ExchangeFilterFunction.class::cast)
.forEach(builder::filter);
}
}
代码示例来源:origin: knowm/XChange
@SuppressWarnings("unchecked")
public static OpenOrders adaptOpenOrders(CoinbaseProOrder[] coinbaseExOpenOrders) {
Stream<Order> orders =
Arrays.asList(coinbaseExOpenOrders).stream().map(CoinbaseProAdapters::adaptOrder);
Map<Boolean, List<Order>> twoTypes =
orders.collect(Collectors.partitioningBy(t -> t instanceof LimitOrder));
@SuppressWarnings("rawtypes")
List limitOrders = twoTypes.get(true);
return new OpenOrders(limitOrders, twoTypes.get(false));
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Map<Boolean, List<Integer>> serial_lazy_jdk()
{
return this.integersJDK.stream().collect(Collectors.partitioningBy(each -> each % 2 == 0));
}
代码示例来源:origin: shekhargulati/99-problems
public static <T> Map<Boolean, List<T>> split(List<T> list, int n) {
return IntStream
.range(0, list.size())
.mapToObj(i -> new SimpleEntry<>(i, list.get(i)))
.collect(partitioningBy(entry -> entry.getKey() < n, mapping(SimpleEntry::getValue, toList())));
}
}
代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises
public Map<Boolean, List<Artist>> bandsAndSolo(Stream<Artist> artists) {
return artists.collect(partitioningBy(artist -> artist.isSolo()));
}
// END BANDS_AND_SOLO
代码示例来源:origin: rest-assured/rest-assured
public static WebTestClientFactory of(Object[] controllersOrConfigurersOrExchangeFilterFunctions) {
Map<Boolean, List<Object>> partitionedByConfigurer = Arrays.stream(controllersOrConfigurersOrExchangeFilterFunctions)
.collect(partitioningBy(WebTestClientConfigurer.class::isInstance));
List<Object> controllersAndExchangeFunctions = partitionedByConfigurer.get(false);
Map<Boolean, List<Object>> partitionedByExchangeFunction = controllersAndExchangeFunctions.stream()
.collect(partitioningBy(ExchangeFilterFunction.class::isInstance));
List<WebTestClientConfigurer> configurers = partitionedByConfigurer.get(true).stream()
.map(WebTestClientConfigurer.class::cast)
.collect(toList());
List<ExchangeFilterFunction> exchangeFilterFunctions = partitionedByExchangeFunction.get(true).stream()
.map(ExchangeFilterFunction.class::cast)
.collect(toList());
WebTestClient.Builder builder = WebTestClient.bindToController(partitionedByExchangeFunction.get(false)
.toArray())
.configureClient();
configurers.forEach(builder::apply);
exchangeFilterFunctions.forEach(builder::filter);
return new BuilderBasedWebTestClientFactory(builder);
}
代码示例来源:origin: dropwizard/dropwizard
.collect(Collectors.partitioningBy(x ->
disabled.stream().noneMatch(pat -> pat.matcher(x).matches()) &&
enabled.stream().anyMatch(pat -> pat.matcher(x).matches()) &&
代码示例来源:origin: google/error-prone
@Override
public OrganizedImports organizeImports(List<Import> imports) {
OrganizedImports organized = new OrganizedImports();
// Group into static and non-static.
Map<Boolean, List<Import>> partionedByStatic =
imports.stream().collect(Collectors.partitioningBy(Import::isStatic));
for (Boolean key : order.groupOrder()) {
organizePartition(organized, partionedByStatic.get(key));
}
return organized;
}
代码示例来源:origin: prestodb/presto
@Override
public PlanNode visitMarkDistinct(MarkDistinctNode node, RewriteContext<Expression> context)
{
Set<Symbol> pushDownableSymbols = ImmutableSet.copyOf(node.getDistinctSymbols());
Map<Boolean, List<Expression>> conjuncts = extractConjuncts(context.get()).stream()
.collect(Collectors.partitioningBy(conjunct -> SymbolsExtractor.extractUnique(conjunct).stream().allMatch(pushDownableSymbols::contains)));
PlanNode rewrittenNode = context.defaultRewrite(node, combineConjuncts(conjuncts.get(true)));
if (!conjuncts.get(false).isEmpty()) {
rewrittenNode = new FilterNode(idAllocator.getNextId(), rewrittenNode, combineConjuncts(conjuncts.get(false)));
}
return rewrittenNode;
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Map<Boolean, List<Integer>> serial_lazy_streams_gsc()
{
return this.integersGSC.stream().collect(Collectors.partitioningBy(each -> each % 2 == 0));
}
代码示例来源:origin: prestodb/presto
@Override
public PlanNode visitGroupId(GroupIdNode node, RewriteContext<Expression> context)
{
Map<Symbol, SymbolReference> commonGroupingSymbolMapping = node.getGroupingColumns().entrySet().stream()
.filter(entry -> node.getCommonGroupingColumns().contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference()));
Predicate<Expression> pushdownEligiblePredicate = conjunct -> SymbolsExtractor.extractUnique(conjunct).stream()
.allMatch(commonGroupingSymbolMapping.keySet()::contains);
Map<Boolean, List<Expression>> conjuncts = extractConjuncts(context.get()).stream().collect(Collectors.partitioningBy(pushdownEligiblePredicate));
// Push down conjuncts from the inherited predicate that apply to common grouping symbols
PlanNode rewrittenNode = context.defaultRewrite(node, inlineSymbols(commonGroupingSymbolMapping, combineConjuncts(conjuncts.get(true))));
// All other conjuncts, if any, will be in the filter node.
if (!conjuncts.get(false).isEmpty()) {
rewrittenNode = new FilterNode(idAllocator.getNextId(), rewrittenNode, combineConjuncts(conjuncts.get(false)));
}
return rewrittenNode;
}
代码示例来源:origin: google/error-prone
@Override
public OrganizedImports organizeImports(List<Import> imports) {
// Group into static and non-static. Each group is a set sorted by type.
Map<Boolean, ImmutableSortedSet<Import>> partionedByStatic =
imports.stream()
.collect(
Collectors.partitioningBy(
Import::isStatic, toImmutableSortedSet(Comparator.comparing(Import::getType))));
return new OrganizedImports()
// Add groups, in the appropriate order.
.addGroups(partionedByStatic, order.groupOrder());
}
}
代码示例来源:origin: yu199195/Raincat
private Map<Boolean, List<TxTransactionItem>> filterData(final List<TxTransactionItem> txTransactionItems) {
//过滤掉发起方的数据,发起方已经进行提交,不需要再通信进行
final List<TxTransactionItem> collect = txTransactionItems.stream()
.filter(item -> item.getRole() == TransactionRoleEnum.ACTOR.getCode())
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) {
return null;
}
return collect.stream().collect(Collectors.partitioningBy(item ->
Objects.equals(Address.getInstance().getDomain(), item.getTmDomain())));
}
代码示例来源:origin: Vedenin/useful-java-links
Map<Boolean, List<Integer>> parts = numbers.stream().collect(Collectors.partitioningBy((p) -> p % 2 == 0));
System.out.println("parts = " + parts); // print parts = {false=[1, 3], true=[2, 4]}
代码示例来源:origin: prestodb/presto
@Override
public PlanNode visitProject(ProjectNode node, RewriteContext<Expression> context)
{
Set<Symbol> deterministicSymbols = node.getAssignments().entrySet().stream()
.filter(entry -> DeterminismEvaluator.isDeterministic(entry.getValue()))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
Predicate<Expression> deterministic = conjunct -> SymbolsExtractor.extractUnique(conjunct).stream()
.allMatch(deterministicSymbols::contains);
Map<Boolean, List<Expression>> conjuncts = extractConjuncts(context.get()).stream().collect(Collectors.partitioningBy(deterministic));
// Push down conjuncts from the inherited predicate that only depend on deterministic assignments with
// certain limitations.
List<Expression> deterministicConjuncts = conjuncts.get(true);
// We partition the expressions in the deterministicConjuncts into two lists, and only inline the
// expressions that are in the inlining targets list.
Map<Boolean, List<Expression>> inlineConjuncts = deterministicConjuncts.stream()
.collect(Collectors.partitioningBy(expression -> isInliningCandidate(expression, node)));
List<Expression> inlinedDeterministicConjuncts = inlineConjuncts.get(true).stream()
.map(entry -> inlineSymbols(node.getAssignments().getMap(), entry))
.collect(Collectors.toList());
PlanNode rewrittenNode = context.defaultRewrite(node, combineConjuncts(inlinedDeterministicConjuncts));
// All deterministic conjuncts that contains non-inlining targets, and non-deterministic conjuncts,
// if any, will be in the filter node.
List<Expression> nonInliningConjuncts = inlineConjuncts.get(false);
nonInliningConjuncts.addAll(conjuncts.get(false));
if (!nonInliningConjuncts.isEmpty()) {
rewrittenNode = new FilterNode(idAllocator.getNextId(), rewrittenNode, combineConjuncts(nonInliningConjuncts));
}
return rewrittenNode;
}
代码示例来源:origin: prestodb/presto
@Override
public PlanNode visitWindow(WindowNode node, RewriteContext<Expression> context)
{
List<Symbol> partitionSymbols = node.getPartitionBy();
// TODO: This could be broader. We can push down conjucts if they are constant for all rows in a window partition.
// The simplest way to guarantee this is if the conjucts are deterministic functions of the partitioning symbols.
// This can leave out cases where they're both functions of some set of common expressions and the partitioning
// function is injective, but that's a rare case. The majority of window nodes are expected to be partitioned by
// pre-projected symbols.
Predicate<Expression> isSupported = conjunct ->
DeterminismEvaluator.isDeterministic(conjunct) &&
SymbolsExtractor.extractUnique(conjunct).stream()
.allMatch(partitionSymbols::contains);
Map<Boolean, List<Expression>> conjuncts = extractConjuncts(context.get()).stream().collect(Collectors.partitioningBy(isSupported));
PlanNode rewrittenNode = context.defaultRewrite(node, combineConjuncts(conjuncts.get(true)));
if (!conjuncts.get(false).isEmpty()) {
rewrittenNode = new FilterNode(idAllocator.getNextId(), rewrittenNode, combineConjuncts(conjuncts.get(false)));
}
return rewrittenNode;
}
代码示例来源:origin: zalando/zalenium
public synchronized void cleanupDashboard() throws IOException {
List<TestInformation> informationList = loadTestInformationFromFile();
Map<Boolean, List<TestInformation>> partitioned = informationList.stream()
.collect(Collectors.partitioningBy(testInformation -> testInformation.getRetentionDate().getTime() > new Date().getTime()));
List<TestInformation> validTestsInformation = partitioned.get(true);
List<TestInformation> invalidTestsInformation = partitioned.get(false);
if(invalidTestsInformation.size() > 0) {
LOGGER.info("Cleaning up " + invalidTestsInformation.size() + " test(s) from Dashboard");
for(TestInformation testInformation : invalidTestsInformation) {
deleteIfExists(new File(getLocalVideosPath() + "/" + testInformation.getFileName()));
deleteIfExists(new File(testInformation.getLogsFolderPath()));
}
cleanupFiles(false);
dumpTestInformationToFile(validTestsInformation);
}
}
代码示例来源:origin: prestodb/presto
.collect(Collectors.partitioningBy(PlanNodeDecorrelator.DecorrelatingVisitor.this::isCorrelated));
List<Expression> correlatedPredicates = ImmutableList.copyOf(predicates.get(true));
List<Expression> uncorrelatedPredicates = ImmutableList.copyOf(predicates.get(false));
代码示例来源:origin: apache/nifi
.collect(Collectors.partitioningBy(record -> record.getType() == RepositoryRecordType.CLEANUP_TRANSIENT_CLAIMS));
内容来源于网络,如有侵权,请联系作者删除!