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:nu.yona.server.goals.service.ActivityCategoryService.java

@Cacheable(value = "activityCategorySet", key = "'instance'")
@Transactional//  w w  w . j  a va2  s.com
public Set<ActivityCategoryDto> getAllActivityCategories() {
    // Sort the collection to make it simpler to compare the activity categories
    return StreamSupport.stream(repository.findAll().spliterator(), false)
            .map(ActivityCategoryDto::createInstance)
            .collect(Collectors
                    .toCollection(() -> new TreeSet<>((Comparator<ActivityCategoryDto> & Serializable) (l,
                            r) -> l.getName().compareTo(r.getName()))));
}

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

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

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

/**
 * convert AnnotationDatas to AnnotationDataResources
 *
 * @param annotations entities//w ww .  j a v  a2s .  co  m
 * @return List of resources
 */
@Override
public List<AnnotationDataResource> toResources(Iterable<? extends AnnotationData> 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());
}

From source file:edu.pitt.dbmi.ccd.anno.vocabulary.attribute.AttributeResourceAssembler.java

/**
 * convert Attributes to AttributeResources
 *
 * @param attributes entities/*from w w  w.  j av  a 2 s .c o  m*/
 * @return List of resources
 */
@Override
public List<AttributeResource> toResources(Iterable<? extends Attribute> attributes) {
    // Assert attributes is not empty
    Assert.isTrue(attributes.iterator().hasNext());
    return StreamSupport.stream(attributes.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}

From source file:com.company.et.service.JsonService.java

/**
 *  ??  Json'a   ?-json'/*from   w  w  w.java  2 s  .  co  m*/
 * @param jsonArray
 * @return ??  ? Json
 * @throws IOException 
 */
public static List<String> split(final String jsonArray) throws IOException {
    final JsonNode jsonNode = new ObjectMapper().readTree(jsonArray);
    return StreamSupport.stream(jsonNode.spliterator(), false).map(JsonNode::toString)
            .collect(Collectors.toList());
}

From source file:com.davidmogar.alsa.services.schedule.internal.ScheduleManagerServiceImpl.java

@Override
public List<ScheduleDto> findByDate(Date date) {
    return StreamSupport.stream(scheduleDataService.findByDate(date).spliterator(), false).map(ScheduleDto::new)
            .collect(Collectors.toList());
}

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

public void writeCorpus() {
    OutputStream out = null;//from w  w  w.  j  a va2 s.c  o m
    try {
        if (writer != null) {
            out = new BufferedOutputStream(new FileOutputStream(testFile));
            writer.writeCorpus(corpus, out);
        } else if (consumer != null) {
            StreamSupport.stream(Spliterators.spliterator(corpus.iterator(), corpus.getNumberOfDocuments(),
                    Spliterator.DISTINCT & Spliterator.NONNULL), false).forEach(consumer);
        } else {
            Assert.fail("Test is misconfigured since writer==null and consumer==null.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Got an Exception: " + e.getLocalizedMessage());
    } finally {
        IOUtils.closeQuietly(out);
        if ((consumer != null) && (consumer instanceof Closeable)) {
            IOUtils.closeQuietly((Closeable) consumer);
        }
    }
}

From source file:org.mskcc.shenkers.data.interval.GIntervalTree.java

public Stream<IntervalFeature> streamOverlaps(String chr, int start, int end) {
    boolean parallel = false;
    int characteristics = 0;
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(query(chr, start, end), characteristics),
            parallel);//from   w ww  .  j  av  a  2  s . c  o m
}

From source file:org.graylog2.indexer.cluster.jest.JestUtils.java

private static List<JsonObject> extractRootCauses(JsonObject jsonObject) {
    return Optional.of(jsonObject).map(json -> asJsonObject(json.get("error")))
            .map(error -> asJsonArray(error.get("root_cause"))).map(Iterable::spliterator)
            .map(x -> StreamSupport.stream(x, false)).orElse(Stream.empty()).map(GsonUtils::asJsonObject)
            .collect(Collectors.toList());
}

From source file:example.springdata.rest.stores.StarbucksClient.java

@Test
public void discoverStoreSearch() {

    Traverson traverson = new Traverson(URI.create(String.format(SERVICE_URI, port)), MediaTypes.HAL_JSON);

    // Set up path traversal
    TraversalBuilder builder = traverson. //
            follow("stores", "search", "by-location");

    // Log discovered
    log.info("");
    log.info("Discovered link: {}", builder.asTemplatedLink());
    log.info("");

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("location", "40.740337,-73.995146");
    parameters.put("distance", "0.5miles");

    PagedResources<Resource<Store>> resources = builder.//
            withTemplateParameters(parameters).//
            toObject(new PagedResourcesType<Resource<Store>>() {
            });/*from  w  w w  . j  a  v  a 2 s  .c o m*/

    PageMetadata metadata = resources.getMetadata();

    log.info("Got {} of {} stores: ", resources.getContent().size(), metadata.getTotalElements());

    StreamSupport.stream(resources.spliterator(), false).//
            map(Resource::getContent).//
            forEach(store -> log.info("{} - {}", store.name, store.address));
}