Example usage for java.util.stream Collectors toList

List of usage examples for java.util.stream Collectors toList

Introduction

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

Prototype

public static <T> Collector<T, ?, List<T>> toList() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new List .

Usage

From source file:com.haulmont.cuba.core.sys.jpql.Parser.java

public static List<JoinVariableNode> parseJoinClause(String join) throws RecognitionException {
    JPA2Parser parser = createParser(join);
    JPA2Parser.join_section_return aReturn = parser.join_section();
    CommonTree tree = (CommonTree) aReturn.getTree();
    if (tree == null) {
        parser = createParser("join " + join);
        aReturn = parser.join_section();
        tree = (CommonTree) aReturn.getTree();
    }//from w w w.  j  a  v  a  2s . com
    if (tree instanceof JoinVariableNode) {
        checkTreeForExceptions(join, tree);
        return Collections.singletonList((JoinVariableNode) tree);
    } else {
        List<JoinVariableNode> joins = tree.getChildren().stream()
                .filter(node -> node instanceof JoinVariableNode).map(JoinVariableNode.class::cast)
                .collect(Collectors.toList());
        checkTreeForExceptions(join, tree);
        return joins;
    }
}

From source file:com.orange.clara.cloud.truststore.CertificateJsonDeserializer.java

@Override
public List<Certificate> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        final List<String> certificates = mapper.readValue(jp, new TypeReference<List<String>>() {
        });/*from  ww w.  j a v a  2  s  .c o m*/
        final List<Certificate> collect = certificates.stream().map(e -> CertificateFactory.newInstance(e))
                .collect(Collectors.toList());
        return collect;
    } else {
        //consume this stream
        mapper.readTree(jp);
        return new ArrayList<Certificate>();
    }
}

From source file:com.github.drbookings.ui.BookingsByOrigin.java

public Collection<T> getAirbnbBookings() {
    return bookingEntries.stream().filter(AIRBNB_FILTER).collect(Collectors.toList());
}

From source file:de.mgd.simplesoundboard.dao.FileSystemSoundResourceDao.java

@Override
public List<String> findSoundCategories() {
    List<File> files = findFilesInStorageDirectoryIfAny(this::isSoundCategory);
    if (files.isEmpty()) {
        return Collections.emptyList();
    }//w  w  w.  j a v a2s  .  c o  m

    files.sort(NameFileComparator.NAME_INSENSITIVE_COMPARATOR);
    return files.stream().map(File::getName).collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.igor.jenkins.JenkinsCache.java

public List<String> getJobNames(String master) {
    List<String> jobs = new ArrayList<>();
    redisClientDelegate.withKeyScan(prefix() + ":" + master + ":*", 1000, page -> jobs
            .addAll(page.getResults().stream().map(JenkinsCache::extractJobName).collect(Collectors.toList())));
    jobs.sort(Comparator.naturalOrder());
    return jobs;//from   ww  w.  ja  va  2  s .c o m
}

From source file:com.neu.controller.SearchController.java

@RequestMapping(value = "/search.htm", method = RequestMethod.GET, headers = "Accept=*/*", produces = "application/json")
@ResponseStatus(HttpStatus.OK)//w w w .jav a2  s. c om
public @ResponseBody String searchresult(HttpServletRequest request) throws Exception {
    System.out.println("in drugsearch controller");
    String action = request.getParameter("action");
    List<Drugs> drugs;
    String csvFile = "UserSearch.csv";
    String rpath = request.getRealPath("/");
    rpath = rpath + "/dataFiles/" + csvFile;

    Pattern pattern = Pattern.compile(",");

    BufferedReader in = new BufferedReader(new FileReader(rpath));
    drugs = in.lines().skip(1).map(line -> {
        String[] x = pattern.split(line);
        return new Drugs(x[0], x[3]);
    }).collect(Collectors.toList());
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
    mapper.writeValue(System.out, drugs);

    //            Drugs drug=new Drugs("AZ","sn");
    return mapper.writeValueAsString(drugs);
}

From source file:com.hp.octane.integrations.testhelpers.OctaneSecuritySimulationUtils.java

static private Cookie createSecurityCookie(String client, String secret) {
    Cookie result = new Cookie(SECURITY_COOKIE_NAME, String.join(SECURITY_TOKEN_SEPARATOR, Stream
            .of(client, secret, String.valueOf(System.currentTimeMillis())).collect(Collectors.toList())));
    result.setHttpOnly(true);//from  w w  w.  j  a v  a2s  .  c o m
    result.setDomain(".localhost");
    return result;
}

From source file:org.openlmis.fulfillment.web.util.ProofOfDeliveryDtoBuilder.java

/**
 * Create a new list of {@link ProofOfDeliveryDto} based on data
 * from {@link Shipment}./* w ww . j  av a2 s  .c o  m*/
 *
 * @param pods collection used to create {@link ProofOfDeliveryDto} list (can be {@code null})
 * @return new list of {@link ProofOfDeliveryDto}. Empty list if passed argument is {@code null}.
 */
public List<ProofOfDeliveryDto> build(Collection<ProofOfDelivery> pods) {
    if (null == pods) {
        return Collections.emptyList();
    }
    return pods.stream().map(this::export).collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.LocalDeployer.java

@Override
public RemoteAction deploy(LocalServiceProvider serviceProvider, DeploymentDetails deploymentDetails,
        GenerateService.ResolvedConfiguration resolvedConfiguration, List<String> serviceNames) {
    List<LocalService> enabledServices = serviceProvider.getLocalServices(serviceNames).stream()
            .filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled())
            .collect(Collectors.toList());

    Map<String, String> installCommands = enabledServices.stream().reduce(new HashMap<>(),
            (commands, installable) -> {
                String command = String.join("\n", installable.installArtifactCommand(deploymentDetails),
                        installable.stageProfilesCommand(resolvedConfiguration));
                commands.put(installable.getService().getCanonicalName(), command);
                return commands;
            }, (m1, m2) -> {/*from   w w w .  j av a  2  s  .c  o m*/
                m1.putAll(m2);
                return m1;
            });

    String installCommand = serviceProvider.getInstallCommand(resolvedConfiguration, installCommands);
    RemoteAction result = new RemoteAction();
    result.setAutoRun(true);
    result.setScript(installCommand);
    return result;
}

From source file:com.klaussoft.springtest.CostumerController.java

@RequestMapping("/costumer")
public Costumer costumer(@RequestParam(value = "name", defaultValue = "World") String cname) {

    log.info("Creating tables");

    jdbcTemplate.execute("DROP TABLE customers IF EXISTS");
    jdbcTemplate/*from   w ww . java2  s . c  o m*/
            .execute("CREATE TABLE customers(" + "id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))");

    // Split up the array of whole names into an array of first/last names
    List<Object[]> splitUpNames = Arrays.asList("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long").stream()
            .map(name -> name.split(" ")).collect(Collectors.toList());

    // Use a Java 8 stream to print out each tuple of the list
    splitUpNames
            .forEach(name -> log.info(String.format("Inserting customer record for %s %s", name[0], name[1])));

    // Uses JdbcTemplate's batchUpdate operation to bulk load data
    jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames);

    log.info("Querying for customer records where first_name = 'Josh':");
    jdbcTemplate
            .query("SELECT id, first_name, last_name FROM customers WHERE first_name = ?",
                    new Object[] { "Josh" }, (rs, rowNum) -> new Costumer(rs.getLong("id"),
                            rs.getString("first_name"), rs.getString("last_name")))
            .forEach(customer -> log.info(customer.toString()));

    return null;
}