/** * Returns a sequential {@link Stream} of the remaining contents of {@code iterator}. Do not use * {@code iterator} directly after passing it to this method. */ public static <T> Stream<T> stream(Iterator<T> iterator) { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false); }
public static <T> List<T> reverse_customStream(ArrayDeque<T> list) { if (list == null) { throw new IllegalArgumentException("list can't be null"); } return StreamSupport.stream(Spliterators.spliteratorUnknownSize(list.descendingIterator(), Spliterator.ORDERED), false).collect(toList()); }
/** * Accumulates the elements of stream into a new Set. * @param stream the {@code java.util.stream.BaseStream} * @param <T> the type of element * @return a new {@code java.util.Set} instance */ public static <T> Set<T> toSet(BaseStream<T, ? extends BaseStream> stream) { return StreamSupport.stream( Spliterators.spliteratorUnknownSize(stream.iterator(), Spliterator.ORDERED), false).collect(Collectors.<T>toSet()); }
/** {@inheritDoc} */ @Override public Iterator<IgniteBiTuple<String, ModelDescriptor>> iterator() { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(models.iterator(), Spliterator.ORDERED), false) .map(e -> new IgniteBiTuple<>(e.getKey(), e.getValue())) .iterator(); } }
private void updateTestExecutionFromTestPlan(final InputFile inputFile) { final MutableTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile); if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) { return; } long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count(); measureCache.put(inputFile.key(), TESTS_KEY, new DefaultMeasure<Integer>().forMetric(TESTS).withValue((int) nonSkippedTests)); long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).mapToLong(t -> t.durationInMs() != null ? t.durationInMs().longValue() : 0L).sum(); measureCache.put(inputFile.key(), TEST_EXECUTION_TIME_KEY, new DefaultMeasure<Long>().forMetric(TEST_EXECUTION_TIME).withValue(executionTime)); long errorTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.ERROR).count(); measureCache.put(inputFile.key(), TEST_ERRORS_KEY, new DefaultMeasure<Integer>().forMetric(TEST_ERRORS).withValue((int) errorTests)); long skippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.SKIPPED).count(); measureCache.put(inputFile.key(), SKIPPED_TESTS_KEY, new DefaultMeasure<Integer>().forMetric(SKIPPED_TESTS).withValue((int) skippedTests)); long failedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.FAILURE).count(); measureCache.put(inputFile.key(), TEST_FAILURES_KEY, new DefaultMeasure<Integer>().forMetric(TEST_FAILURES).withValue((int) failedTests)); }
/** * Accumulates the elements of stream into a new List. * @param stream the {@code java.util.stream.BaseStream} * @param <T> the type of element * @return a new {@code java.util.List} instance */ public static <T> List<T> toList(BaseStream<T, ? extends BaseStream> stream) { return StreamSupport.stream( Spliterators.spliteratorUnknownSize(stream.iterator(), Spliterator.ORDERED), false).collect(Collectors.<T>toList()); }
private static Stream<SentimentDatum> imdb(String path, SentimentClass label) { return StreamSupport.stream( IOUtils.iterFilesRecursive(new File(path)).spliterator(), true) .map(x -> { try { return new SentimentDatum(IOUtils.slurpFile(x), label); } catch (IOException e) { throw new RuntimeIOException(e); } }); }
/** * Joins {@code codeBlocks} into a single {@link CodeBlock}, each separated by {@code separator}. * For example, joining {@code String s}, {@code Object o} and {@code int i} using {@code ", "} * would produce {@code String s, Object o, int i}. */ public static CodeBlock join(Iterable<CodeBlock> codeBlocks, String separator) { return StreamSupport.stream(codeBlocks.spliterator(), false).collect(joining(separator)); }
/** * Returns a sequential {@link Stream} of the remaining contents of {@code iterator}. Do not use * {@code iterator} directly after passing it to this method. */ public static <T> Stream<T> stream(Iterator<T> iterator) { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false); }