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.homeadvisor.kafdrop.model.ConsumerVO.java

public List<ConsumerRegistrationVO> getActiveInstancesForTopic(String topic) {
    return activeInstances.stream().filter(reg -> reg.getSubscriptions().containsKey(topic))
            .collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.halyard.config.services.v1.LookupService.java

/**
 * Given a node filter and a node type, find all nodes that match both the filter and the type of the Node.
 * @param filter is the filter to lookup by.
 * @param clazz is the class of the node type we want to find.
 * @return the nodes matching the filter and clazz.
 *//*  w ww .  j a  va 2 s .  c  o m*/
public <T extends Node> List<T> getMatchingNodesOfType(NodeFilter filter, Class<T> clazz) {
    Halconfig halconfig = parser.getHalconfig();

    return getMatchingNodes(halconfig, filter).stream().filter(clazz::isInstance).map(n -> (T) n)
            .collect(Collectors.toList());
}

From source file:com.haulmont.cuba.gui.app.core.appproperties.AppPropertiesDatasource.java

@Override
protected Collection<AppPropertyEntity> getEntities(Map<String, Object> params) {
    List<AppPropertyEntity> entities = loadAppPropertyEntities();

    String name = (String) params.get("name");
    if (StringUtils.isNotEmpty(name)) {
        entities = entities.stream().filter(it -> it.getName().toLowerCase().contains(name.toLowerCase()))
                .collect(Collectors.toList());
    }/*from w w  w  . j  a va 2 s  .c  om*/

    return createEntitiesTree(entities);
}

From source file:org.mytms.common.dao.querydsl.QSort.java

/**
 * Converts the given {@link OrderSpecifier}s into a list of {@link Order}s.
 * //from   ww  w .ja v a2s.co m
 * @param orderSpecifiers must not be {@literal null} or empty.
 * @return
 */
private static List<Order> toOrders(List<OrderSpecifier<?>> orderSpecifiers) {

    Assert.notNull(orderSpecifiers, "Order specifiers must not be null!");

    return orderSpecifiers.stream().map(QSort::toOrder).collect(Collectors.toList());
}

From source file:de.sainth.recipe.backend.db.repositories.UnitRepository.java

public List<Unit> findAll() {
    return create
            .selectFrom(UNITS).fetch().stream().map(record -> new Unit(record.getShortname(),
                    record.getLongname(), record.getConversionFactor(), record.getBasicUnit()))
            .collect(Collectors.toList());
}

From source file:com.nebhale.buildmonitor.web.ControllerUtils.java

@ExceptionHandler(ConstraintViolationException.class)
ResponseEntity<Set<String>> handleConstraintViolation(ConstraintViolationException e) {
    Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations();

    Set<String> messages = new HashSet<>(constraintViolations.size());
    messages.addAll(constraintViolations.stream()
            .map(constraintViolation -> String.format("%s value '%s' %s", constraintViolation.getPropertyPath(),
                    constraintViolation.getInvalidValue(), constraintViolation.getMessage()))
            .collect(Collectors.toList()));

    return new ResponseEntity<>(messages, HttpStatus.BAD_REQUEST);
}

From source file:io.knotx.dataobjects.Fragment.java

public Fragment(JsonObject fragment) {
    this.knots = fragment.getJsonArray(KNOTS_KEY).stream().map(String::valueOf).collect(Collectors.toList());
    this.content = fragment.getString(CONTENT_KEY);
    this.context = fragment.getJsonObject(CONTEXT_KEY, new JsonObject());
}

From source file:com.twosigma.jupyter.security.HashedMessageAuthenticationCode.java

public String sign(List<String> msg) {
    List<byte[]> collect = msg.stream().map(String::getBytes).collect(Collectors.toList());
    return signBytes(collect);
}

From source file:indexer.Index.java

public List<IndexDocument> runQuery(Query q, int maxResults) {
    IndexReader reader = getIndexer().getReader();
    IndexSearcher searcher = new IndexSearcher(reader);
    try {/*from w w w. java 2s .co m*/
        TopDocs docs = searcher.search(q, maxResults);
        return Arrays.asList(docs.scoreDocs).stream().map(s -> {
            try {
                int uniqueId = Integer.parseInt(reader.document(s.doc).get(IndexerFields.ID.name()));
                return new IndexDocument(uniqueId, s.doc, s.score);
            } catch (IOException e) {
                log.error("Error while converting document", e);
                return null;
            }
        }).filter(d -> d != null).collect(Collectors.toList());

    } catch (IOException e) {
        log.error("There was an error while attempting a search.", e);
        return Collections.checkedList(new ArrayList<>(), IndexDocument.class);
    }
}

From source file:io.github.swagger2markup.internal.component.TagsComponent.java

@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.TAGS));

    List<String> tagsList = params.tags.stream().map(this::mapToString).collect(Collectors.toList());

    if (config.getTagOrdering() != null)
        Collections.sort(tagsList, config.getTagOrdering());

    markupDocBuilder.unorderedList(tagsList);

    return markupDocBuilder;
}