Example usage for java.util.stream StreamSupport stream

List of usage examples for java.util.stream StreamSupport stream

Introduction

In this page you can find the example usage for java.util.stream StreamSupport stream.

Prototype

public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) 

Source Link

Document

Creates a new sequential or parallel Stream from a Spliterator .

Usage

From source file:net.hamnaberg.json.Item.java

static List<Item> fromArray(JsonNode queries) {
    return Collections.unmodifiableList(StreamSupport.stream(queries.spliterator(), false)
            .map(query -> new Item((ObjectNode) query)).collect(Collectors.toList()));
}

From source file:com.epam.ta.reportportal.commons.Preconditions.java

/**
 * Checks whether iterable contains elements matchers provided predicate
 * //w w  w .  j a va  2 s.  c o m
 * @param filter
 * @return
 */
public static <T> Predicate<Iterable<T>> contains(final Predicate<T> filter) {
    return iterable -> StreamSupport.stream(iterable.spliterator(), false).anyMatch(filter);
}

From source file:com.epam.ta.reportportal.events.handler.ExternalSystemActivityHandler.java

@EventListener
public void onProjectExternalSystemsDelete(ProjectExternalSystemsDeletedEvent event) {
    Iterable<ExternalSystem> externalSystems = event.getExternalSystems();
    if (null != externalSystems) {
        List<Activity> activities = StreamSupport.stream(externalSystems.spliterator(), false)
                .map(externalSystem -> {
                    String name = externalSystem.getExternalSystemType().name() + ":"
                            + externalSystem.getProject();
                    return activityBuilder.get().addObjectName(name).addObjectType(EXTERNAL_SYSTEM)
                            .addLoggedObjectRef(externalSystem.getId()).addUserRef(event.getDeletedBy())
                            .addActionType(DELETE).addProjectRef(event.getProject()).build();
                }).collect(Collectors.toList());
        if (!activities.isEmpty())
            activityRepository.save(activities);
    }// w w w . ja v a 2s.  c o m
}

From source file:com.coinblesk.server.service.KeyService.java

@Transactional(readOnly = true)
public List<Keys> allKeys() {
    return StreamSupport.stream(keyRepository.findAll().spliterator(), false).collect(Collectors.toList());
}

From source file:Main.java

private Future<?> getOperationResult(List<BlockingQueue<T>> queues, Function<Stream<T>, ?> f) {
    BlockingQueue<T> queue = new LinkedBlockingQueue<>();
    queues.add(queue);//from w w w.  j a v a2s .c  o  m
    Spliterator<T> spliterator = new BlockingQueueSpliterator<>(queue);
    Stream<T> source = StreamSupport.stream(spliterator, false);
    return CompletableFuture.supplyAsync(() -> f.apply(source));
}

From source file:org.dice_research.topicmodeling.io.test.AbstractCorpusIOTest.java

public Corpus readCorpus() {
    InputStream in = null;/*  w w  w .j  a  v  a 2s  .  co m*/
    try {
        if (reader != null) {
            in = new BufferedInputStream(new FileInputStream(testFile));
            reader.readCorpus(in);
            return reader.getCorpus();
        } else if (supplier != null) {
            return new DocumentListCorpus<List<Document>>(StreamSupport
                    .stream(Spliterators.spliteratorUnknownSize(new DocumentSupplierAsIterator(supplier),
                            Spliterator.DISTINCT & Spliterator.NONNULL), false)
                    .collect(Collectors.toList()));
        } else {
            Assert.fail("Test is misconfigured since reader==null and supplier==null.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Got an Exception: " + e.getLocalizedMessage());
    } finally {
        IOUtils.closeQuietly(in);
    }
    return null;
}

From source file:com.streamsets.pipeline.lib.parser.excel.WorkbookParser.java

private static <T> Stream<T> stream(Iterable<T> it) {
    return StreamSupport.stream(it.spliterator(), false);
}

From source file:com.epam.ta.reportportal.events.handler.TicketActivitySubscriber.java

@EventListener
public void onTicketAttached(TicketAttachedEvent event) {
    List<Activity> activities = new ArrayList<>();
    String separator = ",";
    Iterable<TestItem> testItems = event.getBefore();
    Map<String, Activity.FieldValues> results = StreamSupport.stream(testItems.spliterator(), false)
            .filter(item -> null != item.getIssue())
            .collect(Collectors.toMap(TestItem::getId, item -> Activity.FieldValues.newOne()
                    .withOldValue(issuesIdsToString(item.getIssue().getExternalSystemIssues(), separator))));

    Iterable<TestItem> updated = event.getAfter();

    for (TestItem testItem : updated) {
        if (null == testItem.getIssue())
            continue;
        Activity.FieldValues fieldValues = results.get(testItem.getId());
        fieldValues.withNewValue(issuesIdsToString(testItem.getIssue().getExternalSystemIssues(), separator));

        Activity activity = activityBuilder.get().addProjectRef(event.getProject()).addActionType(ATTACH_ISSUE)
                .addLoggedObjectRef(testItem.getId()).addObjectType(TestItem.TEST_ITEM)
                .addUserRef(event.getPostedBy()).addHistory(ImmutableMap.<String, Activity.FieldValues>builder()
                        .put(TICKET_ID, fieldValues).build())
                .build();//from  www. java2s .  c o m
        activities.add(activity);
    }
    activityRepository.save(activities);
}

From source file:com.crossover.trial.weather.domain.DomainRepositoryTest.java

@Test
@DatabaseSetup("classpath:dbtest/airport_big.xml")
public void testFindInRangeBig() {
    long count = StreamSupport.stream(airportRepository.findInRadius(valueOf("BOS"), 500).spliterator(), false)
            .count();/*from  w  ww . ja va  2 s.c  o  m*/

    assertThat(count, equalTo(429L));
}

From source file:edu.pitt.dbmi.ccd.anno.annotation.AnnotationResourceAssembler.java

/**
 * convert Annotations to AnnotationResources
 *
 * @param annotations entities//from   w  w  w  . jav  a2 s .c  om
 * @return list of resources
 */
@Override
public List<AnnotationResource> toResources(Iterable<? extends Annotation> annotations)
        throws IllegalArgumentException {
    // Assert annotations is not empty
    Assert.isTrue(annotations.iterator().hasNext());
    return StreamSupport.stream(annotations.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}