Example usage for java.util Map forEach

List of usage examples for java.util Map forEach

Introduction

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

Prototype

default void forEach(BiConsumer<? super K, ? super V> action) 

Source Link

Document

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.

Usage

From source file:org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder.java

private static void addHandlers(ShowPromptNode showPromptNode, Map<String, Object> handlersMap) {

    if (handlersMap == null) {
        return;//  w w  w  .  j  ava2 s  .c o m
    }
    handlersMap.forEach((key, value) -> {
        if (value instanceof ScriptObjectMirror) {
            SerializableJsFunction jsFunction = SerializableJsFunction
                    .toSerializableForm((ScriptObjectMirror) value);
            if (jsFunction != null) {
                showPromptNode.addHandler(key, jsFunction);
            } else {
                log.error("Event handler : " + key + " is not a function : " + value);
            }
        } else if (value instanceof SerializableJsFunction) {
            showPromptNode.addHandler(key, (SerializableJsFunction) value);
        }
    });
}

From source file:org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder.java

private static FailNode createFailNode(String url, Map<String, Object> parameterMap) {

    FailNode failNode = new FailNode();
    failNode.setErrorPageUri(url);/*from ww w . jav a 2  s. co  m*/

    parameterMap.forEach((key, value) -> failNode.getFailureData().put(key, String.valueOf(value)));
    return failNode;
}

From source file:org.dbflute.solr.cbean.SolrQueryBuilder.java

public static String dismax(String query, Map<SolrDBMeta, Integer> qf) {
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("{!dismax qf='");
    qf.forEach((field, weight) -> {
        queryBuilder.append(field.fieldName());
        if (weight != null) {
            queryBuilder.append("^");
            queryBuilder.append(weight);
        }/*  w  w  w . j ava 2  s .co m*/
        queryBuilder.append(" ");
    });
    if (queryBuilder.length() != 0) {
        queryBuilder.deleteCharAt(queryBuilder.length() - 1);
    }
    queryBuilder.append("'}");
    queryBuilder.append(query);

    return queryBuilder.toString();
}

From source file:org.springframework.cloud.gcp.autoconfigure.core.cloudfoundry.GcpCloudFoundryEnvironmentPostProcessor.java

@SuppressWarnings("unchecked")
private static Properties retrieveCfProperties(Map<String, Object> vcapMap, String gcpServiceName,
        String cfServiceName, Map<String, String> fieldsToMap) {
    Properties properties = new Properties();

    try {// w ww  .  j  a v a2  s .c  om
        List<Object> serviceBindings = (List<Object>) vcapMap.get(cfServiceName);

        if (serviceBindings == null) {
            return properties;
        }

        if (serviceBindings.size() != 1) {
            LOGGER.warn("The service " + cfServiceName + " has to be bound to a "
                    + "Cloud Foundry application once and only once.");
            return properties;
        }

        Map<String, Object> serviceBinding = (Map<String, Object>) serviceBindings.get(0);
        Map<String, String> credentialsMap = (Map<String, String>) serviceBinding.get("credentials");
        String prefix = SPRING_CLOUD_GCP_PROPERTY_PREFIX + gcpServiceName + ".";
        fieldsToMap.forEach(
                (cfPropKey, gcpPropKey) -> properties.put(prefix + gcpPropKey, credentialsMap.get(cfPropKey)));
    } catch (ClassCastException ex) {
        LOGGER.warn("Unexpected format of CF (VCAP) properties", ex);
    }

    return properties;
}

From source file:org.apache.accumulo.core.conf.SiteConfiguration.java

@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "location of props is specified by an admin")
private static ImmutableMap<String, String> createMap(URL accumuloPropsLocation,
        Map<String, String> overrides) {
    CompositeConfiguration config = new CompositeConfiguration();
    config.setThrowExceptionOnMissing(false);
    config.setDelimiterParsingDisabled(true);
    PropertiesConfiguration propsConfig = new PropertiesConfiguration();
    propsConfig.setDelimiterParsingDisabled(true);
    if (accumuloPropsLocation != null) {
        try {/*  www.  java 2 s. c o m*/
            propsConfig.load(accumuloPropsLocation.openStream());
        } catch (IOException | ConfigurationException e) {
            throw new IllegalArgumentException(e);
        }
    }
    config.addConfiguration(propsConfig);

    // Add all properties in config file
    Map<String, String> result = new HashMap<>();
    config.getKeys().forEachRemaining(key -> result.put(key, config.getString(key)));

    // Add all overrides
    overrides.forEach(result::put);

    // Add sensitive properties from credential provider (if set)
    String credProvider = result.get(Property.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS.getKey());
    if (credProvider != null) {
        org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
        hadoopConf.set(CredentialProviderFactoryShim.CREDENTIAL_PROVIDER_PATH, credProvider);
        for (Property property : Property.values()) {
            if (property.isSensitive()) {
                char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf,
                        property.getKey());
                if (value != null) {
                    result.put(property.getKey(), new String(value));
                }
            }
        }
    }
    return ImmutableMap.copyOf(result);
}

From source file:gov.hhs.onc.crigtt.config.impl.CrigttConfiguration.java

public void setConfigurationProperties(Map<String, ?> configProps) {
    configProps.forEach(this::setConfigurationProperty);
}

From source file:com.wormsim.data.GroupDistribution.java

GroupDistribution(AnimalZoo2Instance p_zoo, Map<String, IntegerDistribution> p_group_dists) {
    dists = new HashMap<>(p_group_dists.size());
    p_group_dists.forEach((k, v) -> {
        dists.put(p_zoo.getAnimalStage(k), v);
    });//  www.java2s.  com
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TestMultithreadedTableProvider.java

private static Map<String, String> buildOffsetMap(Map<TableRuntimeContext, Map<String, String>> partitions,
        final boolean preNonIncremental) {
    final Map<String, String> offsets = new HashMap<>();
    partitions.forEach((part, off) -> {
        String offsetKey = part.getOffsetKey();
        if (preNonIncremental) {
            // before non-incremental mode, offset keys didn't have the final portion (usingNonIncrementalLoad)
            // so remove the final term
            final int index = StringUtils.lastIndexOf(offsetKey, TableRuntimeContext.OFFSET_TERM_SEPARATOR);
            offsetKey = offsetKey.substring(0, index);
        }/*w  w  w. j a  va 2s .c om*/
        offsets.put(offsetKey, off == null ? null : OffsetQueryUtil.getOffsetFormat(off));
    });
    return offsets;
}

From source file:com.addthis.hydra.job.alert.JobAlertRunner.java

@VisibleForTesting
static AlertWebhookRequest getWebhookObject(Spawn spawn, AbstractJobAlert jobAlert, String alertLink,
        String reason, Map<String, String> errors) {

    // Turn all the jobs in error into a list of information about each job

    AlertWebhookRequest webhookRequest = new AlertWebhookRequest();
    webhookRequest.setAlertType(jobAlert.getTypeString());
    webhookRequest.setAlertLink(alertLink);
    webhookRequest.setAlertReason(reason.trim());
    webhookRequest.setAlertDescription(jobAlert.description);

    errors.forEach((jobUUID, errMsg) -> {

        JobError jobError = new JobError();
        jobError.setId(jobUUID);//w  w  w.  j  a va2  s .c  o m
        jobError.setError(errMsg);
        jobError.setClusterHead(clusterHead);

        Job job = spawn.getJob(jobUUID);

        if (job != null) {
            jobError.setJobState(job.getState());
            jobError.setDescription(job.getDescription());

            if (job.getStartTime() != null) {
                jobError.setStartTime(job.getStartTime());
            }

            if (job.getEndTime() != null) {
                jobError.setEndTime(job.getEndTime());
            }

            List<JobTask> jobTasks = job.getCopyOfTasks();
            jobError.setNodeCount(jobTasks.size());
            jobError.setErrorCount(
                    (int) jobTasks.stream().filter(t -> t.getState() == JobTaskState.ERROR).count());
        }

        webhookRequest.getJobsInError().add(jobError);
    });

    return webhookRequest;
}

From source file:org.hyperledger.fabric.sdk.testutils.TestUtils.java

/**
 * Just for testing remove all peers and orderers and add them back.
 *
 * @param client/*  w w w  .j  a  va  2  s  .c o  m*/
 * @param channel
 */
public static void testRemovingAddingPeersOrderers(HFClient client, Channel channel) {
    Map<Peer, Channel.PeerOptions> perm = new HashMap<>();

    assertTrue(channel.isInitialized());
    assertFalse(channel.isShutdown());

    try {
        Thread.sleep(1500); // time needed let channel get config block
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }

    channel.getPeers().forEach(peer -> {
        try {
            perm.put(peer, channel.getPeersOptions(peer));
            channel.removePeer(peer);
        } catch (InvalidArgumentException e) {
            throw new RuntimeException(e);
        }
    });

    perm.forEach((peer, value) -> {
        try {

            Peer newPeer = client.newPeer(peer.getName(), peer.getUrl(), peer.getProperties());
            channel.addPeer(newPeer, value);

        } catch (InvalidArgumentException e) {
            throw new RuntimeException(e);
        }
    });

    List<Orderer> removedOrders = new ArrayList<>();

    for (Orderer orderer : channel.getOrderers()) {
        try {
            channel.removeOrderer(orderer);
            removedOrders.add(orderer);
        } catch (InvalidArgumentException e) {
            throw new RuntimeException(e);
        }

    }
    removedOrders.forEach(orderer -> {
        try {
            Orderer newOrderer = client.newOrderer(orderer.getName(), orderer.getUrl(),
                    orderer.getProperties());
            channel.addOrderer(newOrderer);
        } catch (InvalidArgumentException e) {
            throw new RuntimeException(e);
        }

    });
}