Example usage for java.util Collection forEach

List of usage examples for java.util Collection forEach

Introduction

In this page you can find the example usage for java.util Collection 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:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java

@Test
@Ignore/*  w  w  w. j a  v  a 2  s  .c  om*/
public void testGetBranches() throws SourceConnectorException, BitbucketException {
    String team = "apicurio";
    String repo = "apicurio-test";

    Collection<SourceCodeBranch> branches = service.getBranches(team, repo);
    Assert.assertNotNull(branches);
    Assert.assertFalse(branches.isEmpty());

    branches.forEach(branch -> {
        System.out.println("Found branch: " + branch.getName() + " -- " + branch.getCommitId());
    });
}

From source file:com.baidu.rigel.biplatform.ma.report.utils.QueryUtils.java

/**
 * ?//ww  w .  j av  a 2 s .  c  o  m
 * @param request
 * @param model
 */
public static Map<String, Object> resetContextParam(final HttpServletRequest request, ReportDesignModel model) {
    Map<String, Object> rs = Maps.newHashMap();
    Collection<ReportParam> params = DeepcopyUtils.deepCopy(model.getParams()).values();
    if (params.size() == 0) {
        return rs;
    }
    LOG.info("context params ============== " + ContextManager.getParams());
    Map<String, String> requestParams = collectRequestParams(params, request);
    rs.putAll(requestParams);
    LOG.info("current request params ============== " + requestParams);
    params.forEach(param -> {
        LOG.info("current param define ============== " + param.toString());
        if (param.isNeeded() && StringUtils.isEmpty(requestParams.get(param.getName()))) {
            if (StringUtils.isEmpty(param.getDefaultValue())) {
                throw new RuntimeException("??");
            }
            rs.put(param.getElementId(), param.getDefaultValue());
            rs.put(param.getName(), param.getDefaultValue());
        } else if (!StringUtils.isEmpty(requestParams.get(param.getName()))) {
            rs.put(param.getElementId(), requestParams.get(param.getName()));
        } else if (!StringUtils.isEmpty(param.getDefaultValue())) {
            rs.put(param.getElementId(), param.getDefaultValue());
            rs.put(param.getName(), param.getDefaultValue());
        }
    });
    LOG.info("after reset params is : " + rs);
    return rs;
}

From source file:org.sonar.server.rule.RuleUpdater.java

private void deleteActiveRuleParams(DbSession dbSession, String key,
        Collection<ActiveRuleParamDto> activeRuleParamDtos) {
    activeRuleParamDtos.forEach(new DeleteActiveRuleParams(dbSession, dbClient, key));
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.PhotoInspectorImpl.java

private void updateTagPicker(Collection<Photo> photos) {
    tagPicker.getEntities().clear();/*  w  w w  .j a  va  2  s .c om*/
    photos.forEach((photo) -> {
        Set<String> tags = photo.getData().getTags().stream().map(Tag::getName).collect(Collectors.toSet());
        tagPicker.getEntities().add(tags);
    });
}

From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java

@Override
public void saveOrUpdate(Collection<T> entities) {
    entities.forEach(entity -> {
        saveOrUpdate(entity);
    });
}

From source file:com.netflix.genie.agent.execution.statemachine.StateMachineAutoConfiguration.java

private void registerListeners(final Collection<JobExecutionListener> listeners,
        final StateMachine<States, Events> stateMachine) {
    // Add state machine listeners
    listeners.forEach(stateMachine::addStateListener);

    // Add state action listeners to each state
    for (JobExecutionListener listener : listeners) {
        stateMachine.addStateListener(listener);
        for (State<States, Events> state : stateMachine.getStates()) {
            state.addActionListener(listener);
        }/*w ww . ja  v a  2  s  .co  m*/
    }
}

From source file:org.thingsboard.server.dao.timeseries.BaseTimeseriesService.java

@Override
public ListenableFuture<List<TsKvEntry>> findLatest(TenantId tenantId, EntityId entityId,
        Collection<String> keys) {
    validate(entityId);/*www  . jav  a 2s. c o m*/
    List<ListenableFuture<TsKvEntry>> futures = Lists.newArrayListWithExpectedSize(keys.size());
    keys.forEach(key -> Validator.validateString(key, "Incorrect key " + key));
    if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) {
        EntityView entityView = entityViewService.findEntityViewById(tenantId, (EntityViewId) entityId);
        List<String> filteredKeys = new ArrayList<>(keys);
        if (entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null
                && !entityView.getKeys().getTimeseries().isEmpty()) {
            filteredKeys.retainAll(entityView.getKeys().getTimeseries());
        }
        List<ReadTsKvQuery> queries = filteredKeys.stream().map(key -> {
            long endTs = entityView.getEndTimeMs() != 0 ? entityView.getEndTimeMs() : Long.MAX_VALUE;
            return new BaseReadTsKvQuery(key, entityView.getStartTimeMs(), endTs, 1, "DESC");
        }).collect(Collectors.toList());

        if (queries.size() > 0) {
            return timeseriesDao.findAllAsync(tenantId, entityView.getEntityId(), queries);
        } else {
            return Futures.immediateFuture(new ArrayList<>());
        }
    }
    keys.forEach(key -> futures.add(timeseriesDao.findLatest(tenantId, entityId, key)));
    return Futures.allAsList(futures);
}

From source file:com.netflix.spinnaker.fiat.permissions.DefaultPermissionsResolver.java

private Map<String, Collection<Role>> getAndMergeUserRoles(@NonNull Collection<ExternalUser> users) {
    List<String> usernames = users.stream().map(ExternalUser::getId).collect(Collectors.toList());

    Map<String, Collection<Role>> userToRoles = userRolesProvider.multiLoadRoles(usernames);

    users.forEach(user -> {
        userToRoles.computeIfAbsent(user.getId(), ignored -> new ArrayList<>()).addAll(user.getExternalRoles());
    });/*from ww  w.j a v  a2  s  . c  om*/

    if (log.isDebugEnabled()) {
        try {
            log.debug("Multi-loaded roles: \n"
                    + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(userToRoles));
        } catch (Exception e) {
            log.debug("Exception writing roles", e);
        }
    }
    return userToRoles;
}

From source file:de.ks.text.view.AsciiDocViewer.java

public void preload(Collection<AsciiDocContent> load) {
    ActivityExecutor executorService = controller.getExecutorService();
    JavaFXExecutorService javaFXExecutor = controller.getJavaFXExecutor();
    load.forEach(t -> {
        CompletableFuture<Pair<String, String>> completableFuture = CompletableFuture
                .supplyAsync(() -> preProcess(t.getAdoc()), executorService)//
                .thenApply(desc -> {//ww  w. j  av a 2s .c o m
                    if (desc == null || desc.trim().isEmpty()) {
                        return "";
                    } else {
                        return parser.parse(desc);
                    }
                })//
                .thenApply(html -> Pair.of(t.getIdentifier(), html));
        completableFuture.thenApply(pair -> {
            preloaded.put(pair.getKey(), pair.getValue());
            return pair;
        }).thenAcceptAsync(pair -> {
            if (currentIdentifier.getValueSafe().equals(pair.getKey())) {
                String html = pair.getValue();
                currentHtml.set(html);
                webView.getEngine().loadContent(html);
            }
        }, javaFXExecutor)//
                .exceptionally(e -> {
                    log.error("Could not parse adoc", e);
                    return null;
                });
    });
}

From source file:org.springframework.kafka.core.KafkaAdmin.java

private void addTopicsIfNeeded(AdminClient adminClient, Collection<NewTopic> topics) {
    if (topics.size() > 0) {
        Map<String, NewTopic> topicNameToTopic = new HashMap<>();
        topics.forEach(t -> topicNameToTopic.compute(t.name(), (k, v) -> v = t));
        DescribeTopicsResult topicInfo = adminClient
                .describeTopics(topics.stream().map(NewTopic::name).collect(Collectors.toList()));
        List<NewTopic> topicsToAdd = new ArrayList<>();
        Map<String, NewPartitions> topicsToModify = checkPartitions(topicNameToTopic, topicInfo, topicsToAdd);
        if (topicsToAdd.size() > 0) {
            addTopics(adminClient, topicsToAdd);
        }//  ww w. j  a v a  2 s .c o m
        if (topicsToModify.size() > 0) {
            modifyTopics(adminClient, topicsToModify);
        }
    }
}