Example usage for java.util List forEach

List of usage examples for java.util List forEach

Introduction

In this page you can find the example usage for java.util List forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:org.moserp.inventory.rest.InventoryController.java

@RequestMapping(method = RequestMethod.GET, value = "/inventoryItems/search/findByProductIdOrFacilityId")
public Resources<Resource<InventoryItem>> findByProductIdOrFacilityId(
        @RequestParam(required = false) String productId, @RequestParam(required = false) String facilityId) {
    List<InventoryItem> items;
    RestUri facilityBaseUri = moduleRegistry.getBaseUriForResource(OtherResources.FACILITIES);
    RestUri facilityUri = facilityBaseUri.slash(facilityId);
    RestUri productsBaseUri = moduleRegistry.getBaseUriForResource(OtherResources.PRODUCTS);
    RestUri productUri = productsBaseUri.slash(productId);
    if (productId == null) {
        items = repository.findByFacility(facilityUri);
    } else if (facilityId == null) {
        items = repository.findByProductInstanceProduct(productUri);
    } else {//from  w w  w  .jav a  2s .  c om
        Query query = query(where("productInstance.product").is(productUri.getUri()).and("facility")
                .is(facilityUri.getUri()));
        items = mongoTemplate.find(query, InventoryItem.class);
    }
    Stream<Resource<InventoryItem>> resourceStream = items.stream()
            .map(inventoryItem -> new Resource<>(inventoryItem));
    List<Resource<InventoryItem>> inventoryItemResources = resourceStream.collect(Collectors.toList());
    inventoryItemResources.forEach(inventoryItemLinks::addLinks);
    return new Resources<>(inventoryItemResources);
}

From source file:io.github.jeddict.db.modeler.spec.DBSchema.java

/**
 * @param tables the tables to set
 */
public void setTables(List<DBTable> tables) {
    tables.forEach(t -> addTable(t));
}

From source file:com.ibm.watson.catalyst.jumpqa.splitter.Splitter.java

@Override
public final List<String> split(final List<String> strings) {
    final List<String> result = new ArrayList<String>();
    strings.forEach((string) -> {
        result.addAll(split(string));//from   ww w.  j a v a2 s.  co m
    });
    return result;
}

From source file:org.openlmis.fulfillment.web.shipmentdraft.ShipmentDraftDtoBuilder.java

private List<ShipmentLineItemDto> exportToDtos(List<ShipmentDraftLineItem> lineItems) {
    List<ShipmentLineItemDto> lineItemDtos = new ArrayList<>(lineItems.size());
    lineItems.forEach(l -> lineItemDtos.add(exportToDto(l)));
    return lineItemDtos;
}

From source file:acmi.l2.clientmod.xdat.Controller.java

private static TreeItem<Object> createTreeItem(IOEntity o) {
    TreeItem<Object> item = new TreeItem<>(o);

    List<Field> fields = new ArrayList<>();
    Class<?> clazz = o.getClass();
    while (clazz != Object.class) {
        Arrays.stream(clazz.getDeclaredFields()).filter(field -> !field.isSynthetic())
                .filter(field -> List.class.isAssignableFrom(field.getType())
                        || IOEntity.class.isAssignableFrom(field.getType()))
                .forEach(fields::add);/*from   w  ww. ja v a2 s  .c o m*/
        clazz = clazz.getSuperclass();
    }
    fields.forEach(field -> {
        field.setAccessible(true);

        Optional<Object> obj = Optional.empty();
        try {
            obj = Optional.ofNullable(field.get(o));
        } catch (IllegalAccessException e) {
            log.log(Level.WARNING, String.format("%s.%s is not accessible", o.getClass(), field.getName()), e);
            Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                    String.format("%s.%s is not accessible", o.getClass(), field.getName()));
        }

        obj.ifPresent(val -> {
            if (List.class.isAssignableFrom(field.getType())) {
                if (!field.isAnnotationPresent(Type.class)) {
                    log.log(Level.WARNING,
                            String.format("%s.%s: @Type not defined", o.getClass().getName(), field.getName()));
                    Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                            String.format("%s.%s: @Type not defined", o.getClass().getName(), field.getName()));
                } else {
                    List<IOEntity> list = (List<IOEntity>) val;
                    Class<? extends IOEntity> type = field.getAnnotation(Type.class).value()
                            .asSubclass(IOEntity.class);
                    TreeItem<Object> listItem = new TreeItem<>(new ListHolder(o, list, field.getName(), type));

                    item.getChildren().add(listItem);

                    listItem.getChildren()
                            .addAll(list.stream().map(Controller::createTreeItem).collect(Collectors.toList()));
                }
            } else if (IOEntity.class.isAssignableFrom(field.getType())) {
                IOEntity ioEntity = (IOEntity) val;

                item.getChildren().add(createTreeItem(ioEntity));
            }
        });
    });
    return item;
}

From source file:fr.lepellerin.ecole.service.internal.UtilisateurServiceImpl.java

@Override
@Transactional(readOnly = false)//  ww  w .  jav a  2  s.co  m
public void creerUserPourFamille() {
    final List<Famille> familles = this.familleRepository.findWithoutUserAccount();
    familles.forEach(fam -> {
        final User user = new User();
        user.setFamille(fam);
        user.setEnabled(true);
        user.setRole(Role.ROLE_FAMILLE);
        user.setUsername(fam.getInternetIdentifiant());
        user.setPassword(this.passwordEncoder.encode(fam.getInternetMdp()));
        this.userRepository.save(user);
    });
}

From source file:org.lendingclub.mercator.bind.BindScanner.java

private void scanZones() {

    Instant startTime = Instant.now();

    List<String> zones = getBindClient().getZones();

    zones.forEach(zone -> {

        String cypher = "MERGE (m:BindHostedZone {zoneName:{zone}}) "
                + "ON CREATE SET m.createTs = timestamp(), m.updateTs=timestamp() "
                + "ON MATCH SET  m.updateTs=timestamp();";
        getProjector().getNeoRxClient().execCypher(cypher, "zone", zone);
    });/* w  ww  . j  av  a 2  s  .  c o m*/
    Instant endTime = Instant.now();
    logger.info(" Took {} secs to project Bind Zone information to Neo4j",
            Duration.between(startTime, endTime).getSeconds());

}

From source file:org.shredzone.cilla.core.event.EventServiceImpl.java

@Override
public void fireEvent(Event<?> event) {
    if (log.isDebugEnabled()) {
        log.debug("Sending event " + event.getType() + ", source = " + event.getSource());
    }//from ww w .  ja v a 2  s  .c  o m

    List<EventInvoker> listeners = invokerMap.get(event.getType());
    if (listeners != null) {
        listeners.forEach(invoker -> invoker.invoke(event));
    }
}

From source file:com.edduarte.argus.stopper.FileStopper.java

private boolean load(String language) {
    File stopwordsFile = new File(Constants.STOPWORDS_DIR, language + ".txt");
    if (stopwordsFile.exists()) {
        try (InputStream is = new FileInputStream(stopwordsFile); Parser parser = new SimpleParser()) {

            Set<MutableString> stopwordsAux = new HashSet<>();
            List<String> lines = IOUtils.readLines(is);
            lines.forEach(line -> {
                line = line.trim().toLowerCase();
                if (!line.isEmpty()) {
                    int indexOfPipe = line.indexOf('|');

                    MutableString stopwordLine;
                    if (indexOfPipe == -1) {
                        // there are no pipes in this line
                        // -> add the whole line as a stopword
                        stopwordLine = new MutableString(line);

                    } else if (indexOfPipe > 0) {
                        // there is a pipe in this line and it's not the first char
                        // -> add everything from index 0 to the pipe's index
                        String word = line.substring(0, indexOfPipe).trim();
                        stopwordLine = new MutableString(word);
                    } else {
                        return;
                    }/*from   w  ww  .j  a v a2s  .c  o  m*/

                    Set<MutableString> stopwordsAtLine = parser.parse(stopwordLine).parallelStream()
                            .map(sw -> sw.text).collect(Collectors.toSet());
                    stopwordsAux.addAll(stopwordsAtLine);
                }
            });

            stopwords = ImmutableSet.copyOf(stopwordsAux);
            return true;

        } catch (IOException e) {
            logger.error("There was a problem loading the stopword file.", e);
            stopwords = Collections.emptySet();
        }
    }

    return false;
}

From source file:com.watchrabbit.crawler.batch.service.TaskScheduler.java

@Scheduled(fixedDelayString = "${crawler.batch.delay:10000}")
public void execute() {
    try {//  www  . j  a  v a 2  s.c  o  m
        LOGGER.info("Starting address job");

        List<String> queue = dispatcherServiceFacade.getQueue(maxQueueProcessingSize);
        if (queue.size() > 0) {
            List<List<String>> partition = Lists.partition(queue,
                    queue.size() / dispatcherServiceFacade.getInstanceCount());
            partition.forEach(dispatcherServiceFacade::dispatch);
        }
    } catch (RuntimeException e) {
        LOGGER.error("Address job exception", e);
    }
}