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:com.evolveum.midpoint.model.impl.lens.EvaluationOrderImpl.java

@Override
public Map<QName, Integer> diff(EvaluationOrder newState) {
    if (!newState.isDefined()) {
        throw new IllegalArgumentException("Cannot compute diff to undefined evaluation order");
    }/*from  w w  w  . ja  v a 2 s .  c  o  m*/
    @SuppressWarnings({ "unchecked", "raw" })
    Collection<QName> relations = CollectionUtils.union(getRelations(), newState.getRelations());
    Map<QName, Integer> rv = new HashMap<>();
    // relation is not null below
    relations.forEach(relation -> rv.put(relation,
            newState.getMatchingRelationOrder(relation) - getMatchingRelationOrder(relation)));
    return rv;
}

From source file:io.klerch.alexa.state.handler.AlexaSessionStateHandler.java

/**
 * {@inheritDoc}//from   w w  w  . ja v  a  2 s  .  c  o m
 */
@Override
public void writeModels(final Collection<AlexaStateModel> models) throws AlexaStateException {
    Validate.notNull(models, "Collection of models to write must not be null.");
    models.forEach(model -> {
        try {
            // scope annotations will be ignored as there is only one context you can saveState attributes
            // thus scope will always be session
            session.setAttribute(model.getAttributeKey(), model.toMap(AlexaScope.SESSION));
            log.debug(String.format("Wrote state to session attributes for '%1$s'.", model));
        } catch (final AlexaStateException e) {
            log.error(e);
        }
    });
}

From source file:io.klerch.alexa.state.handler.AlexaSessionStateHandler.java

/**
 * {@inheritDoc}//  w w w .ja  va2 s. c o  m
 */
@Override
public Map<String, AlexaStateObject> readValues(final Collection<String> ids, final AlexaScope scope)
        throws AlexaStateException {
    final Map<String, AlexaScope> idsInScope = new HashMap<>();
    ids.forEach(id -> idsInScope.putIfAbsent(id, scope));
    return readValues(idsInScope);
}

From source file:org.kie.server.services.prometheus.PrometheusKieServerExtension.java

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    this.context = registry;

    registerDefaultDescriptor();/*w ww.j a  v  a 2  s  . co m*/

    //Prometheus Monitoring
    KieServerExtension jBPMExtension = context.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jBPMExtension != null) {

        final KModuleDeploymentService deploymentService = jBPMExtension
                .getAppComponents(KModuleDeploymentService.class);
        if (deploymentService != null) {
            deploymentService.addListener(new PrometheusDeploymentEventListener());
        }

        final ExecutorServiceImpl executorService = jBPMExtension.getAppComponents(ExecutorServiceImpl.class);
        if (executorService != null) {
            executorService.addAsyncJobListener(new PrometheusJobListener());
        }

        final QueryServiceImpl queryService = jBPMExtension.getAppComponents(QueryServiceImpl.class);
        if (queryService != null) {
            final DataSetDefRegistry dataSetDefRegistry = queryService.getDataSetDefRegistry();
            final PrometheusDataSetListener listener = new PrometheusDataSetListener(dataSetDefRegistry);
            listener.init();
            dataSetDefRegistry.addListener(listener);
        }

        final RuntimeDataService dataService = jBPMExtension.getAppComponents(RuntimeDataService.class);
        if (dataService != null) {
            final Collection<ProcessInstanceDesc> processInstances = dataService.getProcessInstances(
                    asList(ProcessInstance.STATE_ACTIVE), null, new QueryContext(0, Integer.MAX_VALUE));
            processInstances
                    .forEach(pi -> recordRunningProcessInstance(pi.getDeploymentId(), pi.getProcessId()));
        }
    }

    KieServerExtension caseExtension = context.getServerExtension(CaseKieServerExtension.EXTENSION_NAME);
    if (caseExtension != null) {
        final CaseManagementRuntimeDataServiceBase caseRuntime = caseExtension
                .getAppComponents(CaseManagementRuntimeDataServiceBase.class);
        if (caseRuntime != null) {
            final CaseInstanceList caseInstances = caseRuntime
                    .getCaseInstances(asList(CaseStatus.OPEN.getName()), 0, Integer.MAX_VALUE, null, false);
            for (CaseInstance instance : caseInstances.getCaseInstances()) {
                recordRunningCaseInstance(instance.getCaseDefinitionId());
            }
        }
    }

    initialized = true;
    LOGGER.info("{} started", toString());
}

From source file:fi.hsl.parkandride.back.RequestLogDao.java

private <T> void insertBatch(Collection<T> batch, RelationalPath<?> expression,
        BiConsumer<SQLInsertClause, T> processor) {
    if (batch.isEmpty()) {
        return;/*from   ww  w  .j a v  a2s  .  com*/
    }
    final SQLInsertClause insert = queryFactory.insert(expression);
    batch.forEach(item -> {
        processor.accept(insert, item);
        insert.addBatch();
    });
    insert.execute();
}

From source file:fi.hsl.parkandride.back.RequestLogDao.java

private <T> void updateBatch(Collection<T> batch, RelationalPath<?> expression,
        BiConsumer<SQLUpdateClause, T> processor) {
    if (batch.isEmpty()) {
        return;//from ww w .ja  va  2  s  . c  o m
    }
    final SQLUpdateClause update = queryFactory.update(expression);
    batch.forEach(item -> {
        processor.accept(update, item);
        update.addBatch();
    });
    update.execute();
}

From source file:com.openshift.internal.restclient.ApiTypeMapper.java

private synchronized void init() {
    if (resourceEndpoints != null) {
        return;/*from  ww w .  ja v  a 2  s  .  com*/
    }
    List<VersionedApiResource> resourceEndpoints = new ArrayList<>();
    Collection<ApiGroup> groups = getLegacyGroups();
    groups.addAll(getApiGroups());
    groups.forEach(g -> {
        Collection<String> versions = g.getVersions();
        versions.forEach(v -> {
            Collection<ModelNode> resources = getResources(g, v);
            addEndpoints(resourceEndpoints, g.getPrefix(), g.getName(), v, resources);
        });
    });
    this.resourceEndpoints = resourceEndpoints;
}

From source file:org.darkware.wpman.security.ChecksumDatabase.java

/**
 * Remove a {@code Collection} of files from the database. This will remove all {@code Paths} in the
 * supplied {@code Collection} from the database.
 * <p>/*  w w w . j  av  a2  s  .c o  m*/
 * <em>Note:</em> Validity checks on the file paths are largely ignored to ensure that a best effort is
 * made to remove all paths that might be in the collection.
 *
 * @param files
 */
public void removeAll(final Collection<Path> files) {
    this.lock.writeLock().lock();
    try {
        files.forEach(this.hashes::remove);
    } finally {
        this.lock.writeLock().unlock();
    }
}

From source file:org.fenixedu.academic.ui.struts.action.administrativeOffice.gradeSubmission.MarkSheetSearchDispatchAction.java

@Atomic(mode = TxMode.WRITE)
private void markAsPrinted(Collection<MarkSheet> markSheets) {
    markSheets.forEach(markSheet -> {
        if (!markSheet.getPrinted()) {
            markSheet.setPrinted(Boolean.TRUE);
        }/*from w w  w.  j  av a  2s.co  m*/
    });
}

From source file:net.dv8tion.jda.core.requests.restaction.PermissionOverrideAction.java

private void checkNull(Collection<?> collection, String name) {
    Checks.notNull(collection, name);//  w w w. j  a  v a 2s .  c o  m
    collection.forEach(e -> Checks.notNull(e, name));
}