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.simiacryptus.util.test.EnglishWords.java

private static void read() {
    try {/*from   w  w  w .  j ava 2  s. co m*/
        InputStream in = Util.cache(url, file);
        String txt = new String(IOUtils.toByteArray(in), "UTF-8").replaceAll("\r", "");
        List<String> list = Arrays.stream(txt.split("\n")).map(x -> x.replaceAll("[^\\w]", ""))
                .collect(Collectors.toList());
        Collections.shuffle(list);
        for (String paragraph : list) {
            queue.add(new EnglishWords(paragraph));
        }
    } catch (final IOException e) {
        // Ignore... end of stream
    } catch (final RuntimeException e) {
        if (!(e.getCause() instanceof InterruptedException))
            throw e;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.bund.bfr.knime.chart.ChartUtils.java

public static List<Color> createColorList(int n) {
    return IntStream.range(0, n).mapToObj(i -> COLORS.get(i % COLORS.size())).collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.echo.artifacts.GitHubArtifactExtractor.java

@Override
public List<Artifact> getArtifacts(String source, Map payload) {
    PushEvent pushEvent = objectMapper.convertValue(payload, PushEvent.class);
    String sha = pushEvent.after;
    Set<String> affectedFiles = pushEvent.commits.stream().map(c -> {
        List<String> fs = new ArrayList<>();
        fs.addAll(c.added);// w w  w.j a  v  a 2  s  . co m
        fs.addAll(c.modified);
        return fs;
    }).flatMap(Collection::stream).collect(Collectors.toSet());

    return affectedFiles.stream()
            .map(f -> Artifact.builder().name(f).version(sha).type("github/file")
                    .reference(pushEvent.repository.contentsUrl.replace("{+path}", f)).build())
            .collect(Collectors.toList());
}

From source file:com.carlomicieli.jtrains.infrastructure.mongo.JongoRepositoryTests.java

@Test
public void shouldFindDocuments() {
    Stream<MyObj> resultStream = repo(jongo()).find(myObjs -> myObjs.find("{'value': 2}"));

    List<MyObj> results = resultStream.collect(Collectors.toList());
    assertThat(results).hasSize(1);// ww w.j  a va 2 s  . c o  m
}

From source file:com.create.application.configuration.EndpointsConfiguration.java

@Bean
public List<String> allowedEndpoints(List<String> actuatorEndpoints, List<String> h2Endpoints,
        List<String> swaggerEndpoints) {
    return Stream.of(actuatorEndpoints, h2Endpoints, swaggerEndpoints).flatMap(Collection::stream)
            .collect(Collectors.toList());
}

From source file:cz.muni.fi.editor.test.service.NotificationServiceIT.java

@Test(expected = FieldException.class)
@WithEditorUser(2L)//from w  w  w  . ja  v a  2 s. c o m
public void markSeenWithWrongID() throws FieldException {
    notificationService.markSeen(Stream.of(new NotificationDTO()).collect(Collectors.toList()));
}

From source file:io.github.carlomicieli.footballdb.starter.parsers.SeasonGamesParser.java

@Override
protected Season parseDocument(Document doc) {
    Stream<Element> rows = gamesTable(doc).flatMap(this::extractTableBody).map(e -> extractRows(e))
            .orElseThrow(() -> new NoSuchElementException("Games table not found"));

    String year = extractYear(doc);
    List<Game> games = rows.map(r -> mapToGame(year, r)).collect(Collectors.toList());
    return new Season(games);
}

From source file:de.whs.poodle.repositories.LectureNoteRepository.java

public List<String> getGroupnames(int courseId) {
    List<String> groupnames = em
            .createQuery("SELECT groupname FROM LectureNote WHERE course.id = :courseId ORDER BY groupname ASC",
                    String.class)
            .setParameter("courseId", courseId).getResultList();
    return groupnames.stream().distinct().collect(Collectors.toList());
}

From source file:com.netflix.genie.core.jpa.specifications.JpaCommandSpecs.java

/**
 * Get a specification using the specified parameters.
 *
 * @param name     The name of the command
 * @param user     The name of the user who created the command
 * @param statuses The status of the command
 * @param tags     The set of tags to search the command for
 * @return A specification object used for querying
 *//*from  w  w  w.jav a  2s . c o  m*/
public static Specification<CommandEntity> find(final String name, final String user,
        final Set<CommandStatus> statuses, final Set<String> tags) {
    return (final Root<CommandEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> {
        final List<Predicate> predicates = new ArrayList<>();
        if (StringUtils.isNotBlank(name)) {
            predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb,
                    root.get(CommandEntity_.name), name));
        }
        if (StringUtils.isNotBlank(user)) {
            predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb,
                    root.get(CommandEntity_.user), user));
        }
        if (statuses != null && !statuses.isEmpty()) {
            final List<Predicate> orPredicates = statuses.stream()
                    .map(status -> cb.equal(root.get(CommandEntity_.status), status))
                    .collect(Collectors.toList());
            predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()])));
        }
        if (tags != null && !tags.isEmpty()) {
            predicates
                    .add(cb.like(root.get(CommandEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags)));
        }
        return cb.and(predicates.toArray(new Predicate[predicates.size()]));
    };
}

From source file:ch.ivyteam.ivy.maven.util.ClasspathJar.java

private static List<String> getClassPathUris(Collection<File> classpathEntries) {
    return classpathEntries.stream().map(file -> file.toURI().toASCIIString()).collect(Collectors.toList());
}