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.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplateProvider.java

@Override
public List<? extends VelocityTemplate> findByType(String type) {
    return getRegisteredTemplates().stream().filter(t -> t.getType().equals(type)).collect(Collectors.toList());
}

From source file:io.yields.math.framework.property.SortedProperty.java

@Override
public boolean isValid(List<T> value, FunctionalContext<List<T>> context) {
    Validate.notEmpty(value, "An empty collection cannot be ordered.");
    int sign = increasing ? 1 : -1;
    List<T> sorted = value.stream().sorted((t1, t2) -> sign * t1.compareTo(t2)).collect(Collectors.toList());
    return IntStream.range(0, value.size())
            .allMatch(index -> comparator.compare(sorted.get(index), value.get(index)) == 0);
}

From source file:org.fenixedu.spaces.ui.ListOccupationsController.java

@RequestMapping
public String list(Model model,
        @RequestParam(defaultValue = "#{new org.joda.time.DateTime().getMonthOfYear()}") int month,
        @RequestParam(defaultValue = "#{new org.joda.time.DateTime().getYear()}") int year,
        @RequestParam(defaultValue = "") String name) {
    DateTime now = new DateTime();
    int currentYear = now.getYear();
    model.addAttribute("years", IntStream.rangeClosed(currentYear - 100, currentYear + 10).boxed()
            .sorted((o1, o2) -> o2.compareTo(o1)).collect(Collectors.toList()));

    List<Partial> months = IntStream.rangeClosed(1, 12).boxed()
            .map(m -> new Partial(DateTimeFieldType.monthOfYear(), m)).collect(Collectors.toList());
    model.addAttribute("months", months);
    model.addAttribute("currentMonth", month);
    model.addAttribute("currentYear", year);
    model.addAttribute("occupations",
            occupationService.getOccupations(month, year, Authenticate.getUser(), name));
    model.addAttribute("name", name);
    return "occupations/list";
}

From source file:com.todo.backend.web.rest.exception.ExceptionResolver.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public @ResponseBody ErrorResponse validationException(HttpServletRequest request,
        MethodArgumentNotValidException exception) {
    if (log.isErrorEnabled()) {
        log.error(exception.getMessage(), exception);
    }/*from   w w w.j  a v  a 2  s.  c  o  m*/
    final List<String> errorCodes = exception.getBindingResult().getFieldErrors().stream()
            .map(e -> String.format("%s.%s.%s", e.getObjectName(), e.getField(), e.getCode()))
            .collect(Collectors.toList());
    return new ErrorResponse(exception.getMessage(), errorCodes);
}

From source file:com.tsguild.videogamewebapp.controller.SearchController.java

@RequestMapping(value = "search/addresses", method = RequestMethod.POST)
@ResponseBody/*from w  w  w  .  ja  va2 s.  c  o  m*/
public List<VideoGame> searchVideoGames(@RequestBody Map<String, String> searchMap) {
    // Create the map of search criteria to send to the DAO
    List<VideoGame> addresses = dao.getAllVideoGames();

    String title = searchMap.get("title");
    String publisher = searchMap.get("publisher");
    String genre = searchMap.get("genre");
    String multiplayer = searchMap.get("multiplayer");
    String rating = searchMap.get("rating");

    // Determine which search terms have values, translate the String
    // keys into SearchTerm enums, and set the corresponding values
    // appropriately.
    if (!title.isEmpty()) {
        addresses = (List<VideoGame>) addresses.stream().filter((VideoGame a) -> {
            String addressFirstName = a.getTitle().toLowerCase();
            String addressSearch = searchMap.get("title");
            return addressFirstName.contains(addressSearch);
        }).collect(Collectors.toList());
    }

    if (!publisher.isEmpty()) {
        addresses = addresses.stream().filter(a -> a.getPublisher().contains(publisher.toLowerCase()))
                .collect(Collectors.toList());
    }

    if (!genre.isEmpty()) {
        addresses = addresses.stream().filter(a -> a.getGenre().contains(genre.toLowerCase()))
                .collect(Collectors.toList());
    }

    if (!rating.isEmpty()) {
        addresses = addresses.stream().filter(a -> a.getEsrbRating().contains(rating.toLowerCase()))
                .collect(Collectors.toList());
    }

    return addresses;
}

From source file:org.obiba.mica.dataset.rest.entity.StudyEntitiesCountService.java

/**
 * Parse the RQL query and translate each node as a Opal query wrapped in a {@link StudyEntitiesCountQuery}.
 *
 * @param query/*w  w w  .  jav a  2s.  c o  m*/
 * @param entityType
 * @return
 */
public List<StudyEntitiesCountQuery> newQueries(String query, String entityType) {
    RQLCriteriaOpalConverter converter = applicationContext.getBean(RQLCriteriaOpalConverter.class);
    converter.parse(query);
    Map<BaseStudy, List<RQLCriterionOpalConverter>> studyConverters = converter.getCriterionConverters()
            .stream().filter(c -> !c.hasMultipleStudyTables()) // TODO include Dataschema variables
            .collect(Collectors.groupingBy(c -> c.getVariableReferences().getStudy()));

    return studyConverters.keySet().stream()
            .map(study -> newQuery(entityType, study, studyConverters.get(study))).collect(Collectors.toList());
}

From source file:am.ik.categolj2.domain.service.book.BookServiceImpl.java

List<BookDto> reseponseToBooks(ItemSearchResponse response) {
    return response.getItems().stream().flatMap(items -> items.getItem().stream()).map(item -> {
        BookDto book = new BookDto();
        ItemAttributes attributes = item.getItemAttributes();
        Image image = item.getMediumImage();
        book.setAsin(item.getASIN());/*from  w ww  . ja v a 2  s . co m*/
        book.setBookLink(item.getDetailPageURL());
        if (image != null) {
            book.setBookImage(image.getURL());
        }
        if (attributes != null) {
            book.setBookTitle(attributes.getTitle());
            book.setAuthors(attributes.getAuthor());
            book.setPublicationDate(attributes.getPublicationDate());
        }
        return book;
    }).collect(Collectors.toList());
}

From source file:com.gemini.domain.repository.impl.GeminiApplicationRepositoryMongoDBImpl.java

public List<GeminiServer> getNetworkServers(String appName, String netStart, String netEnd) {
    List<GeminiNetwork> networks = getAppNetworks(appName);

    List<GeminiNetwork> net = networks.stream().filter(n -> n.getStart().getHostAddress().equals(netStart))
            .filter(n -> n.getEnd().getHostAddress().equals(netEnd)).collect(Collectors.toList());

    if (net != null) {
        return net.get(0).getServers();
    }//w w  w  .ja v  a2  s . co m

    //        for (GeminiNetwork n : networks) {
    //            if (n.getStart().getHostAddress().equals(netStart) && n.getEnd().getHostAddress().equals(netEnd)) {
    //                return n.getServers();
    //            }
    //        }

    return null;
}

From source file:com.epam.catgenome.controller.vo.converter.ProjectConverter.java

/**
 * Converts {@code Project} entity into {@code ProjectVO}
 * @param project {@code Project}//  w w w  .j a v a 2s.c  o m
 * @return {@code ProjectVO}
 */
public static ProjectVO convertTo(final Project project) {
    ProjectVO vo = new ProjectVO();

    vo.setId(project.getId());
    vo.setName(project.getName());
    vo.setCreatedBy(project.getCreatedBy());
    vo.setCreatedDate(project.getCreatedDate());
    vo.setLastOpenedDate(project.getLastOpenedDate());
    vo.setItemsCount(project.getItemsCount());
    vo.setItemsCountPerFormat(project.getItemsCountPerFormat());
    vo.setParentId(project.getParentId());
    vo.setPrettyName(project.getPrettyName());

    if (project.getNestedProjects() != null) {
        vo.setNestedProjects(convertTo(project.getNestedProjects()));
    }

    if (project.getItems() != null) {
        vo.setItems(project.getItems().stream().map(ProjectConverter::convertTo).collect(Collectors.toList()));
    }

    return vo;
}

From source file:org.n52.youngs.test.SpatialSearchIT.java

@BeforeClass
public static void prepareAndStoreSink() throws Exception {
    mapping = new YamlMappingConfiguration(
            Resources.asByteSource(Resources.getResource("mappings/csw-record.yml")).openStream(),
            new XPathHelper());
    //        sink = new ElasticsearchRemoteHttpSink("localhost", 9300, "elasticsearch", mapping.getIndex(), mapping.getType());
    sink = new ElasticsearchClientSink(server.getClient(), "elasticsearhch", mapping.getIndex(),
            mapping.getType());/*from   www . java2s . c o  m*/
    sink.prepare(mapping);
    Mapper mapper = new CswToBuilderMapper(mapping);

    DirectorySource source = new DirectorySource(
            Paths.get(Resources.getResource("records").toURI()).resolve("csw"));
    List<SinkRecord> mappedRecords = source.getRecords(new ReportImpl()).stream().map(mapper::map)
            .collect(Collectors.toList());
    boolean stored = sink.store(mappedRecords);

    Thread.sleep(1000);
    assertThat("all records stored", stored);
}