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:edu.pitt.dbmi.ccd.anno.access.AccessResourceAssembler.java

/**
 * Convert Accesses to AccessResources/*www. j a  v a  2 s .c  om*/
 *
 * @param accesses entities
 * @return list of resources
 */
@Override
public List<AccessResource> toResources(Iterable<? extends Access> accesses) throws IllegalArgumentException {
    // Assert accesses is not empty
    Assert.isTrue(accesses.iterator().hasNext());
    return StreamSupport.stream(accesses.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}

From source file:org.bozzo.ipplan.domain.model.ui.InfrastructureResource.java

/**
 * @param id/*from   w w  w  .j  a v  a 2s  .  c  o m*/
 * @param description
 * @param crm
 * @param group
 */
@JsonCreator
public InfrastructureResource(@JsonProperty("id") Integer id, @JsonProperty String description,
        @JsonProperty String crm, @JsonProperty String group, @JsonProperty Iterable<Zone> zones,
        @JsonProperty Iterable<Subnet> subnets) {
    this.id = id;
    this.description = description;
    this.crm = crm;
    this.group = group;
    if (zones != null) {
        this.setZones(StreamSupport.stream(zones.spliterator(), true).map(new ToZoneResourceFunction()));
    }
    if (subnets != null) {
        this.setSubnets(StreamSupport.stream(subnets.spliterator(), true).map(new ToSubnetResourceFunction()));
    }
}

From source file:io.openshift.booster.service.FruitController.java

@ResponseBody
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<Fruit> getAll() {
    Spliterator<Fruit> fruits = repository.findAll().spliterator();

    return StreamSupport.stream(fruits, false).collect(Collectors.toList());
}

From source file:edu.umd.umiacs.clip.tools.io.BZIP2Files.java

protected static Stream<CSVRecord> records(CSVFormat format, Path path) throws IOException {
    return StreamSupport.stream(format.parse(new BufferedReader(new InputStreamReader(
            new BZip2CompressorInputStream(new BufferedInputStream(newInputStream(path), BUFFER_SIZE)),
            UTF_8.newDecoder().onMalformedInput(IGNORE)))).spliterator(), false);
}

From source file:org.bozzo.ipplan.domain.model.ui.RangeResource.java

/**
 * @param id//  www .  j  av a  2s .c  o  m
 * @param ip
 * @param size
 * @param description
 * @param zoneId
 * @param infraId
 */
@JsonCreator
public RangeResource(@JsonProperty("id") Long id, @JsonProperty Long ip, @JsonProperty Long size,
        @JsonProperty Integer netmask, @JsonProperty String description, @JsonProperty Long zoneId,
        @JsonProperty Integer infraId, @JsonProperty Iterable<Subnet> subnets) {
    super();
    this.id = id;
    this.ip = ip;
    this.size = size;
    this.netmask = netmask;
    this.description = description;
    this.zoneId = zoneId;
    this.infraId = infraId;
    if (subnets != null) {
        this.setSubnets(StreamSupport.stream(subnets.spliterator(), true).map(new ToSubnetResourceFunction()));
    }
}

From source file:com.thinkbiganalytics.config.rest.controller.ConfigurationController.java

/**
 * Get the configuration information//from w w w .  ja va  2 s. com
 *
 * @return A map of name value key pairs
 */
@GET
@Path("/properties")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the current Kylo configuration.")
@ApiResponses({
        @ApiResponse(code = 200, message = "Returns the configuration parameters.", response = Map.class) })
public Response getConfiguration() {
    final Map<String, Object> properties;

    if ((request.getRemoteAddr().equals("127.0.0.1") || request.getRemoteAddr().equals("0:0:0:0:0:0:0:1"))
            && env instanceof AbstractEnvironment) {
        properties = StreamSupport.stream(((AbstractEnvironment) env).getPropertySources().spliterator(), false)
                .filter(source -> source instanceof PropertiesPropertySource)
                .flatMap(source -> ((PropertiesPropertySource) source).getSource().entrySet().stream())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (value1, value2) -> value1));
    } else {
        properties = Collections.emptyMap();
    }

    return Response.ok(properties).build();
}

From source file:com.rationaldevelopers.oss.service.CacheService.java

@Scheduled(fixedRate = 60000)
public void trueUpCache() {
    if (!lock.isLocked()) {
        lock.lock();/*from  www.  ja va  2s.co  m*/
        try {
            LOGGER.info("Running Timed Task");
            final Iterable<SimpleItem> all = simpleItemService.findAll();
            final AtomicInteger itemsUpdated = new AtomicInteger(0);
            StreamSupport.stream(all.spliterator(), false).filter(i -> !cache.containsKey(i.getSid())
                    || cache.containsKey(i.getSid()) && !cache.get(i.getSid()).equals(i)).forEach(i -> {
                        cache.put(i.getSid(), i);
                        itemsUpdated.incrementAndGet();
                    });
            LOGGER.info("Total Items Updated: {}", itemsUpdated.get());
        } finally {
            lock.unlock();
        }
    }
}

From source file:org.sonar.scanner.bootstrap.ScannerPluginPredicate.java

private static List<String> propertyValues(Settings settings, String key, String defaultValue) {
    String s = StringUtils.defaultIfEmpty(settings.getString(key), defaultValue);
    return StreamSupport.stream(Splitter.on(",").trimResults().omitEmptyStrings().split(s).spliterator(), false)
            .collect(Collectors.toList());
}

From source file:com.yahoo.bard.webservice.config.ModuleLoader.java

/**
 * Get a stream of configurations in descending order of precedence given a list of dependent modules.
 *
 * @param dependentModules  The list of modules which are depended on
 *
 * @return A stream of module configurations in descending order of precedence
 *//* www  . j a  v a 2 s.  c o m*/
public Stream<Configuration> getConfigurations(List<String> dependentModules) {
    LOG.debug("Resolving dependent modules: {}", dependentModules);
    ConfigurationGraph graph = loadConfigurationGraph();

    Iterable<String> reverseList = () -> dependentModules.stream()
            .collect(Collectors.toCollection(LinkedList::new)).descendingIterator();

    // Because we want the configurations in precedence order, process the dependent modules from right to left,
    // deduping redundant (repeated with lower precedence) dependencies
    return StreamSupport.stream(reverseList.spliterator(), false).flatMap(graph::preOrderRightToLeftTraversal)
            .distinct().map(graph::getConfiguration);
}

From source file:com.steelbridgelabs.oss.neo4j.Neo4JTestGraphProvider.java

@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName,
        LoadGraphWith.GraphData graphData) {
    // build configuration
    Configuration configuration = Neo4JGraphConfigurationBuilder.connect("localhost", "neo4j", "123")
            .withName(graphName).withElementIdProvider(ElementIdProvider.class).build();
    // create property map from configuration
    Map<String, Object> map = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(configuration.getKeys(),
                    Spliterator.NONNULL | Spliterator.IMMUTABLE), false)
            .collect(Collectors.toMap(key -> key, configuration::getProperty));
    // append class name
    map.put(Graph.GRAPH, Neo4JGraph.class.getName());
    // return configuration map
    return map;/* ww  w .  ja  v a2s  . c om*/
}