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.nebhale.buildmonitor.web.notify.MessagingBuildsChangedNotifier.java

@Override
public void buildsChanged(Project project) {
    List<Resource<Build>> resources = this.repository.findAllByProjectOrderByCreatedDesc(project, PAGE)
            .getContent().stream().map(this.resourceAssembler::toResource).collect(Collectors.toList());

    this.messageTemplate.convertAndSend(getDestination(project), resources);
}

From source file:com.intuit.wasabi.repository.cassandra.ClientConfiguration.java

@Override
public List<String> getNodeHosts() {
    return Arrays.stream(getProperty("nodeHosts", properties).split(",")).map(String::trim)
            .collect(Collectors.toList());
}

From source file:io.wcm.devops.conga.generator.plugins.fileheader.AbstractFileHeader.java

@Override
public final Void apply(FileContext file, FileHeaderContext context) {
    String lineBreak = StringUtils.defaultString(getLineBreak());
    try {/*from  www.  j a  v  a2s .  c o  m*/
        String content = FileUtils.readFileToString(file.getFile(), file.getCharset());

        List<String> sanitizedCommentLines;
        if (context.getCommentLines() == null) {
            sanitizedCommentLines = ImmutableList.of();
        } else {
            sanitizedCommentLines = context.getCommentLines().stream().map(line -> sanitizeComment(line))
                    .filter(line -> line != null)
                    .map(line -> StringUtils.defaultString(getCommentLinePrefix()) + line + lineBreak)
                    .collect(Collectors.toList());
        }

        int insertPosition = getInsertPosition(content);

        content = StringUtils.substring(content, 0, insertPosition)
                + StringUtils.defaultString(getCommentBlockStart())
                + StringUtils.join(sanitizedCommentLines, "") + StringUtils.defaultString(getCommentBlockEnd())
                + StringUtils.defaultString(getBlockSuffix()) + StringUtils.substring(content, insertPosition);

        file.getFile().delete();
        FileUtils.write(file.getFile(), content, file.getCharset());
    } catch (IOException ex) {
        throw new GeneratorException("Unable to add file header to " + FileUtil.getCanonicalPath(file), ex);
    }
    return null;
}

From source file:org.teavm.flavour.example.server.ServerSideProductFacade.java

@Override
public List<ProductDTO> list(ProductQueryDTO query, QueryPageDTO page) {
    JinqStream<Product> all = filtered(query).sortedBy(Product::getName)
            .skip(page.offset != null ? page.offset : 0);
    if (page.limit != null) {
        all = all.limit(page.limit);/*from w  w w. j  av a2s .c o m*/
    }
    return all.map(this::toDTO).collect(Collectors.toList());
}

From source file:pt.ist.fenix.ui.spring.NewsController.java

@RequestMapping
public String news(Model model, @RequestParam(defaultValue = "5", required = false) int posts) {
    model.addAttribute("posts", posts);
    Set<Category> bookmarks = Authenticate.getUser().getBookmarksSet();
    if (!bookmarks.isEmpty()) {
        model.addAttribute("allPosts",
                bookmarks.stream().flatMap(cat -> cat.getPostsSet().stream()).filter(Post::isVisible)
                        .filter(Post::isAccessible).sorted(Post.CREATION_DATE_COMPARATOR).limit(posts)
                        .collect(Collectors.toList()));
    } else if (Bennu.getInstance().getDefaultSite() != null) {
        model.addAttribute("allPosts",
                Bennu.getInstance().getDefaultSite().getPostSet().stream().filter(Post::isVisible)
                        .filter(Post::isAccessible).sorted(Post.CREATION_DATE_COMPARATOR).limit(posts)
                        .collect(Collectors.toList()));
    }/*w  w  w.  java 2  s.com*/
    return "fenix-learning/news";
}

From source file:cloud.api.gateway.ApiGatewayApplication.java

@Bean
UserInfoRestTemplateCustomizer userInfoRestTemplateCustomizer(SpringClientFactory springClientFactory) {
    return template -> {
        AccessTokenProviderChain accessTokenProviderChain = Stream
                .of(new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
                        new ResourceOwnerPasswordAccessTokenProvider(),
                        new ClientCredentialsAccessTokenProvider())
                .peek(tp -> tp.setRequestFactory(new RibbonClientHttpRequestFactory(springClientFactory)))
                .collect(Collectors.collectingAndThen(Collectors.toList(), AccessTokenProviderChain::new));
        template.setAccessTokenProvider(accessTokenProviderChain);
    };//  w  w w .  ja va2s. c  o  m
}

From source file:edu.pitt.dbmi.ccd.db.specification.GroupSpecification.java

private static List<Predicate> notInNameOrDescription(Root<Group> root, CriteriaBuilder cb, Set<String> terms) {
    return terms.stream().map(t -> containsLike(t))
            .map(t -> cb.not(cb.or(nameContains(root, cb, t), descriptionContains(root, cb, t))))
            .collect(Collectors.toList());
}

From source file:gov.ca.cwds.cals.service.FasFacilityService.java

@UnitOfWork(FAS)
List<FacilityInspectionDto> findInspectionsByFacilityId(String licenseNumber) {
    if (StringUtils.isNotBlank(licenseNumber)) {
        return inspectionDao.findDeficienciesByFacilityNumber(licenseNumber).stream()
                .map(facilityInspectionMapper::toFacilityInspectionDto).collect(Collectors.toList());
    }/*from   w w w .  java2s  . c om*/
    return Collections.emptyList();
}

From source file:com.epam.ta.reportportal.ws.converter.builders.ProjectSettingsResourceBuilder.java

public ProjectSettingsResourceBuilder addProjectSettings(Project settings) {
    ProjectSettingsResource resource = getObject();
    resource.setProjectId(settings.getId());
    Map<String, List<IssueSubTypeResource>> result = settings.getConfiguration().getSubTypes().entrySet()
            .stream()//w  ww .j av a  2 s . c om
            .collect(Collectors.toMap(entry -> entry.getKey().getValue(),
                    entry -> entry.getValue().stream()
                            .map(subType -> new IssueSubTypeResource(subType.getLocator(), subType.getTypeRef(),
                                    subType.getLongName(), subType.getShortName(), subType.getHexColor()))
                            .collect(Collectors.toList())));

    resource.setSubTypes(result);
    return this;
}

From source file:pl.edu.icm.comac.vis.server.service.GraphToolkit.java

/**
 * Method to choose appropriate not-favourite nodes of the graph. It takes
 * all nodes outside the normal and large sets, and chooses only those, who
 * are not overflowing the normal nodes over 'itemLinkLimit'. Note, that if 
 * at most one normal node is not overflown by item, others may be.
 *
 * @param normal list of normal favaourite nodes.
 * @param large list of favourite nodes which are overflown, i.e. we have limited
 * knowledge of their links/*from w  w  w  .j  a  v  a2  s  . c o  m*/
 * @param links map of all links for all items, normal and external
 * @param itemLinkLimit recommended size od the links
 * @return set of the items choosen for the graphs as not favourite nodes.
 */
public Set<String> calculateAdditions(Set<String> normal, Set<String> large, Map<String, Set<String>> links,
        long itemLinkLimit) {
    Map<String, Long> outgoingLinks = new HashMap<>();
    normal.stream().forEach(x -> outgoingLinks.put(x, 0l));
    List<String> leftovers = links.keySet().stream().filter(x -> !(normal.contains(x) || large.contains(x)))
            .collect(Collectors.toList());

    //now order list by the link count in each of each element:
    Collections.sort(leftovers, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            int res = -((Integer) links.get(o1).size()).compareTo(((Integer) links.get(o2).size()));
            if (res == 0) {
                return o1.compareToIgnoreCase(o2);
            } else {
                return res;
            }
        }
    });
    Set<String> approved = new HashSet<String>();
    for (String item : leftovers) {
        final Set<String> itemLinks = links.get(item);
        if (itemLinks.stream().anyMatch(x -> {
            return outgoingLinks.containsKey(x) && outgoingLinks.get(x) < itemLinkLimit;
        })) {
            approved.add(item);
            itemLinks.stream().filter(x -> outgoingLinks.containsKey(x))
                    .forEach(x -> outgoingLinks.put(x, outgoingLinks.get(x) + 1));
        }
    }
    return approved;
}