List of usage examples for java.util Map forEach
default void forEach(BiConsumer<? super K, ? super V> action)
From source file:org.ballerinalang.config.ConfigProcessor.java
private static void lookUpVariables(Map<String, Object> configFileEntries) { StringBuilder errMsgBuilder = new StringBuilder(); configFileEntries.forEach((key, val) -> { if (val instanceof Map) { lookUpVariables((Map<String, Object>) val); } else {// w w w . j ava 2s . c o m String envVarVal = getEnvVarValue(key); if (envVarVal != null) { if (val instanceof String) { configFileEntries.put(key, envVarVal); } else if (val instanceof Long) { try { configFileEntries.put(key, Long.parseLong(envVarVal)); } catch (NumberFormatException e) { addErrorMsg(errMsgBuilder, "received invalid int value from environment for", key, envVarVal); } } else if (val instanceof Double) { try { configFileEntries.put(key, Double.parseDouble(envVarVal)); } catch (NumberFormatException e) { addErrorMsg(errMsgBuilder, "received invalid float value from environment for", key, envVarVal); } } else if (val instanceof Boolean) { configFileEntries.put(key, Boolean.parseBoolean(envVarVal)); } } } }); if (errMsgBuilder.length() > 0) { errMsgBuilder.deleteCharAt(errMsgBuilder.length() - 1); throw new IllegalArgumentException(errMsgBuilder.toString()); } }
From source file:org.apache.fluo.recipes.core.combine.it.CombineQueueTreeIT.java
private static Map<String, Long> merge(Map<String, Long> m1, Map<String, Long> m2) { Map<String, Long> ret = new HashMap<>(m1); m2.forEach((k, v) -> ret.merge(k, v, Long::sum)); return ret;/* w w w.j a va2s .c o m*/ }
From source file:com.android.tools.idea.diagnostics.crash.GoogleCrash.java
@NotNull private static MultipartEntityBuilder newMultipartEntityBuilderWithKv(@NotNull Map<String, String> kv) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); kv.forEach(builder::addTextBody); return builder; }
From source file:com.linecorp.armeria.server.docs.Specification.java
static Specification forServiceClasses(Map<Class<?>, Iterable<EndpointInfo>> map, Map<Class<?>, ? extends TBase<?, ?>> sampleRequests) { requireNonNull(map, "map"); final List<ServiceInfo> services = new ArrayList<>(map.size()); final Set<ClassInfo> classes = new HashSet<>(); map.forEach((serviceClass, endpoints) -> { try {//from w w w . java 2s. co m final ServiceInfo service = ServiceInfo.of(serviceClass, endpoints, sampleRequests); services.add(service); classes.addAll(service.classes().values()); } catch (ClassNotFoundException e) { throw new RuntimeException("unable to initialize Specification", e); } }); return new Specification(services, classes); }
From source file:Main.java
public static List<String> getDiff(List<String> source, List<String> target) { if (source.size() == 0 || target.size() == 0) { return null; }// w w w.ja v a 2 s . c om if (source == null || target == null) { return null; } int frequency = 1; List<String> max; List<String> min; List<String> diff = new ArrayList<>(); if (source.size() > target.size()) { max = source; min = target; } else { max = target; min = source; } Map<String, Integer> map = new HashMap<>(); max.stream().forEach(s -> map.put(s, frequency)); min.stream().forEach(s -> { if (map.containsKey(s)) { map.put(s, map.get(s) + 1);//rewrite value } else { map.put(s, frequency); } }); //get value=1 map.forEach((k, v) -> { if (v == 1) { diff.add(k); } }); return diff; }
From source file:ru.anr.base.DockerEngine.java
/** * Converts a plain port binding to the special structure suitable for * processing by the engine./* w ww. j a va 2s . co m*/ * * @param portPairs * The pairs (host,container) for the required ports * @return A {@link Ports} object instance */ public static Ports getBindings(Integer... portPairs) { Map<Integer, Integer> map = toMap(portPairs); final Ports bindings = new Ports(); map.forEach((h, c) -> { bindings.bind(ExposedPort.tcp(c), Ports.Binding(h)); }); return bindings; }
From source file:ee.ria.xroad.proxy.ProxyMain.java
private static void transmuteErrorCodes(Map<String, DiagnosticsStatus> map, int oldErrorCode, int newErrorCode) { map.forEach((key, value) -> { if (value != null && oldErrorCode == value.getReturnCode()) { value.setReturnCodeNow(newErrorCode); }/* w w w . ja v a2s.c om*/ }); }
From source file:org.apache.fluo.recipes.core.export.it.ExportTestBase.java
protected static Set<String> getExportedReferees(String node) { synchronized (globalExports) { Set<String> ret = new HashSet<>(); Map<String, RefInfo> referees = globalExports.get(node); if (referees == null) { return ret; }//from w w w . j a v a 2s .c om referees.forEach((k, v) -> { if (!v.deleted) ret.add(k); }); return ret; } }
From source file:me.ixfan.wechatkit.util.HttpClientUtil.java
/** * POST data using the Content-Type <code>multipart/form-data</code>. * This enables uploading of binary files etc. * * @param url URL of request./* w ww . j a v a 2 s. c o m*/ * @param textInputs Name-Value pairs of text inputs. * @param binaryInputs Name-Value pairs of binary files inputs. * @return JSON object of response. * @throws IOException If I/O error occurs. */ public static JsonObject sendMultipartRequestAndGetJsonResponse(String url, Map<String, String> textInputs, Map<String, MultipartInput> binaryInputs) throws IOException { MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); if (null != textInputs) { textInputs.forEach((k, v) -> multipartEntityBuilder.addTextBody(k, v)); } if (null != binaryInputs) { binaryInputs.forEach((k, v) -> { if (null == v.getDataBytes()) { multipartEntityBuilder.addBinaryBody(k, v.getFile(), v.getContentType(), v.getFile().getName()); } else { multipartEntityBuilder.addBinaryBody(k, v.getDataBytes(), v.getContentType(), v.getFilename()); } }); } CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost post = new HttpPost(url); post.setEntity(multipartEntityBuilder.build()); return httpClient.execute(post, new JsonResponseHandler()); }
From source file:org.apache.samza.storage.ChangelogStreamManager.java
/** * Creates and validates the changelog streams of a samza job. * * @param config the configuration with changelog info. * @param maxChangeLogStreamPartitions the maximum number of changelog stream partitions to create. *///from w w w. j a v a 2s . co m public static void createChangelogStreams(Config config, int maxChangeLogStreamPartitions) { // Get changelog store config StorageConfig storageConfig = new StorageConfig(config); ImmutableMap.Builder<String, SystemStream> storeNameSystemStreamMapBuilder = new ImmutableMap.Builder<>(); storageConfig.getStoreNames().forEach(storeName -> { Optional<String> changelogStream = storageConfig.getChangelogStream(storeName); if (changelogStream.isPresent() && StringUtils.isNotBlank(changelogStream.get())) { storeNameSystemStreamMapBuilder.put(storeName, StreamUtil.getSystemStreamFromNames(changelogStream.get())); } }); Map<String, SystemStream> storeNameSystemStreamMapping = storeNameSystemStreamMapBuilder.build(); // Get SystemAdmin for changelog store's system and attempt to create the stream SystemConfig systemConfig = new SystemConfig(config); storeNameSystemStreamMapping.forEach((storeName, systemStream) -> { // Load system admin for this system. SystemAdmin systemAdmin = systemConfig.getSystemAdmin(systemStream.getSystem()); if (systemAdmin == null) { throw new SamzaException(String.format( "Error creating changelog. Changelog on store %s uses system %s, which is missing from the configuration.", storeName, systemStream.getSystem())); } StreamSpec changelogSpec = StreamSpec.createChangeLogStreamSpec(systemStream.getStream(), systemStream.getSystem(), maxChangeLogStreamPartitions); systemAdmin.start(); if (systemAdmin.createStream(changelogSpec)) { LOG.info(String.format("created changelog stream %s.", systemStream.getStream())); } else { LOG.info(String.format("changelog stream %s already exists.", systemStream.getStream())); } systemAdmin.validateStream(changelogSpec); if (storageConfig.getAccessLogEnabled(storeName)) { String accesslogStream = storageConfig.getAccessLogStream(systemStream.getStream()); StreamSpec accesslogSpec = new StreamSpec(accesslogStream, accesslogStream, systemStream.getSystem(), maxChangeLogStreamPartitions); systemAdmin.createStream(accesslogSpec); systemAdmin.validateStream(accesslogSpec); } systemAdmin.stop(); }); }