/** * Returns a {@code Map<Boolean, List<T>>} which contains two partitions of * the input elements according to a {@code Predicate}. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * <p> * There are no guarantees on the type, mutability, serializability, or * thread-safety of the {@code Map} returned. * * @param predicate a predicate used for classifying input elements * @return a {@code Map<Boolean, List<T>>} which {@link Boolean#TRUE} key is * mapped to the list of the stream elements for which predicate is * true and {@link Boolean#FALSE} key is mapped to the list of all * other stream elements. * * @see #partitioningBy(Predicate, Collector) * @see Collectors#partitioningBy(Predicate) * @since 0.2.2 */ public Map<Boolean, List<T>> partitioningBy(Predicate<? super T> predicate) { return collect(Collectors.partitioningBy(predicate)); }
/** * Returns a collection created by provided supplier function which contains * all the elements of the collections generated by provided mapper from * each element of this stream. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * <p> * This method is equivalent to * {@code flatCollection(mapper).toCollection(supplier)}, but may work * faster. * * @param <U> the type of the elements of the resulting collection * @param <C> the type of the resulting collection * @param mapper a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * function to apply to each element which produces a * {@link Collection} of new values * @param supplier a supplier for the resulting collection * @return the new collection. * @since 0.3.7 */ public <U, C extends Collection<U>> C toFlatCollection(Function<? super T, ? extends Collection<U>> mapper, Supplier<C> supplier) { return map(mapper).collect(supplier, Collection::addAll, Collection::addAll); }
return collect(Collectors.partitioningBy(predicate, Collectors.toCollection(collectionFactory)));
return collect(MoreCollectors.partitioningBy(predicate, downstream));
@SuppressWarnings("unchecked") private List<Job> activateJobs(String jobType, String worker, Duration timeout, int amount) { final Map<String, Object> response = apiRule .createCmdRequest() .type(ValueType.JOB_BATCH, JobBatchIntent.ACTIVATE) .command() .put("type", jobType) .put("worker", worker) .put("timeout", timeout.toMillis()) .put("amount", amount) .put("jobs", Collections.emptyList()) .done() .sendAndAwait() .getValue(); return StreamEx.zip( ((List<Long>) response.get("jobKeys")), ((List<Map<String, Object>>) response.get("jobs")), Job::new) .collect(Collectors.toList()); }
@SuppressWarnings("unchecked") private List<Job> activateJobs(String jobType, String worker, Duration timeout, int amount) { final Map<String, Object> response = apiRule .createCmdRequest() .type(ValueType.JOB_BATCH, JobBatchIntent.ACTIVATE) .command() .put("type", jobType) .put("worker", worker) .put("timeout", timeout.toMillis()) .put("amount", amount) .put("jobs", Collections.emptyList()) .done() .sendAndAwait() .getValue(); return StreamEx.zip( ((List<Long>) response.get("jobKeys")), ((List<Map<String, Object>>) response.get("jobs")), Job::new) .collect(Collectors.toList()); }