List of usage examples for java.util Map forEach
default void forEach(BiConsumer<? super K, ? super V> action)
From source file:org.sonar.java.se.JavaCheckVerifier.java
private void validateFoundFlows(Map<String, List<AnalyzerMessage>> foundFlows) { foundFlows.forEach((flowId, flow) -> validateFlowAttributes(flow, flowId)); }
From source file:io.klerch.alexa.state.handler.AlexaSessionStateHandler.java
/** * {@inheritDoc}/* w w w . j av a 2 s . c om*/ */ @Override public Map<String, AlexaStateObject> readValues(Map<String, AlexaScope> idsInScope) throws AlexaStateException { final Map<String, AlexaStateObject> stateObjectMap = new HashMap<>(); idsInScope.forEach((k, v) -> { // do for session-scoped keys only if (existsInSession(k, v)) { // read from session and wrap value in state object stateObjectMap.putIfAbsent(k, new AlexaStateObject(k, session.getAttribute(k), v)); } }); return stateObjectMap; }
From source file:org.onosproject.drivers.utilities.YangXmlUtils.java
/** * Retrieves a valid XML configuration for a specific XML path for multiple * instance of YangElements objects.//ww w.jav a 2s . c om * * @param file path of the file to be used. * @param elements List of YangElements that are to be set. * @return Hierachical configuration containing XML with values. */ public XMLConfiguration getXmlConfiguration(String file, List<YangElement> elements) { InputStream stream = getCfgInputStream(file); HierarchicalConfiguration cfg = loadXml(stream); XMLConfiguration complete = new XMLConfiguration(); Multimap<String, YangElement> commonElements = ArrayListMultimap.create(); //saves the elements in a Multimap based on the computed key. elements.forEach(element -> { String completeKey = nullIsNotFound(findPath(cfg, element.getBaseKey()), "Yang model does not contain desired path"); commonElements.put(completeKey, element); }); //iterates over the elements and constructs the configuration commonElements.keySet().forEach(key -> { // if there is more than one element for a given path if (commonElements.get(key).size() > 1) { //creates a list of nodes that have to be added for that specific path ArrayList<ConfigurationNode> nodes = new ArrayList<>(); //creates the nodes commonElements.get(key).forEach(element -> nodes.add(getInnerNode(element).getRootNode())); //computes the parent path String parentPath = key.substring(0, key.lastIndexOf(".")); //adds the nodes to the complete configuration complete.addNodes(parentPath, nodes); } else { //since there is only a single element we can assume it's the first one. Map<String, String> keysAndValues = commonElements.get(key).stream().findFirst().get() .getKeysAndValues(); keysAndValues.forEach((k, v) -> complete.setProperty(key + "." + k, v)); } }); addProperties(cfg, complete); return complete; }
From source file:org.onosproject.influxdbmetrics.DefaultInfluxDbMetricsRetriever.java
@Override public Map<NodeId, Map<String, List<InfluxMetric>>> allMetrics(int period, TimeUnit unit) { Map<NodeId, Set<String>> nameMap = allMetricNames(); Map<NodeId, Map<String, List<InfluxMetric>>> metricsMap = Maps.newHashMap(); nameMap.forEach( (nodeId, metricNames) -> metricsMap.putIfAbsent(nodeId, metricsByNodeId(nodeId, period, unit))); return metricsMap; }
From source file:io.fabric8.vertx.maven.plugin.utils.ServiceCombinerUtil.java
/** * The method to perform the service provider combining * * @param jars - the list of jars which needs to scanned for service provider entries * @return - {@link JavaArchive} which has the same service provider entries combined */// w w w. j a va 2 s.co m public JavaArchive combine(List<JavaArchive> jars) { Map<String, Set<String>> locals = findLocalSPI(); Map<String, List<Set<String>>> deps = findSPIsFromDependencies(jars); if (logger.isDebugEnabled()) { logger.debug("SPI declared in the project: " + locals.keySet()); logger.debug("SPI declared in dependencies: " + deps.keySet()); } JavaArchive combinedSPIArchive = ShrinkWrap.create(JavaArchive.class); Set<String> spisToMerge = new HashSet<>(locals.keySet()); spisToMerge.addAll(deps.keySet()); Map<String, List<String>> spis = new HashMap<>(); for (String spi : spisToMerge) { spis.put(spi, merge(spi, locals.get(spi), deps.get(spi))); } if (logger.isDebugEnabled()) { logger.debug("SPI:" + spis.keySet()); } spis.forEach( (name, content) -> combinedSPIArchive.addAsServiceProvider(name, content.toArray(new String[] {}))); return combinedSPIArchive; }
From source file:org.wso2.carbon.transport.file.connector.sender.VFSClientConnector.java
@Override public Object init(CarbonMessage cMsg, CarbonCallback callback, Map<String, Object> properties) throws ClientConnectorException { //TODO: Handle FS options configuration for other protocols as well if (Constants.PROTOCOL_FTP.equals(properties.get("PROTOCOL"))) { properties.forEach((property, value) -> { // TODO: Add support for other FTP related configurations if (Constants.FTP_PASSIVE_MODE.equals(property)) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, (Boolean) value); }/*w w w. ja va 2 s . co m*/ }); } return Boolean.TRUE; }
From source file:org.springframework.beans.factory.config.YamlProcessor.java
@SuppressWarnings("unchecked") private Map<String, Object> asMap(Object object) { // YAML can have numbers as keys Map<String, Object> result = new LinkedHashMap<>(); if (!(object instanceof Map)) { // A document can be a text literal result.put("document", object); return result; }//from w w w . j a v a 2 s . c o m Map<Object, Object> map = (Map<Object, Object>) object; map.forEach((key, value) -> { if (value instanceof Map) { value = asMap(value); } if (key instanceof CharSequence) { result.put(key.toString(), value); } else { // It has to be a map key in this case result.put("[" + key.toString() + "]", value); } }); return result; }
From source file:org.topbraid.jenax.util.ARQFactory.java
/** * Creates SPARQL prefix declarations for a given Model. * @param model the Model to get the prefixes from * @param includeExtraPrefixes true to also include implicit prefixes like afn * @return the prefix declarations/*w w w .ja va2 s .c om*/ */ public String createPrefixDeclarations(Model model, boolean includeExtraPrefixes) { StringBuffer queryString = new StringBuffer(); String defaultNamespace = JenaUtil.getNsPrefixURI(model, ""); if (defaultNamespace != null) { queryString.append("PREFIX : <" + defaultNamespace + ">\n"); } if (includeExtraPrefixes) { Map<String, String> extraPrefixes = ExtraPrefixes.getExtraPrefixes(); for (String prefix : extraPrefixes.keySet()) { String ns = extraPrefixes.get(prefix); perhapsAppend(queryString, prefix, ns, model); } } Map<String, String> map = model.getNsPrefixMap(); map.forEach((prefix, namespace) -> { if (!prefix.isEmpty() && namespace != null) queryString.append("PREFIX " + prefix + ": <" + namespace + ">\n"); }); return queryString.toString(); }
From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java
/** * Create a template configuration according to the supplied {@link Configuration}; if * you already created a template configuration or the supplied {@link Configuration} * contains the property "graph.graphname", we throw a {@link RuntimeException}; you can then use * this template configuration to create a graph using the * ConfiguredGraphFactory create signature and supplying a new graphName. *///from w w w.j av a2 s. c o m public void createTemplateConfiguration(final Configuration config) { Preconditions.checkArgument(!config.containsKey(PROPERTY_GRAPH_NAME), String .format("Your template configuration may not contain the property \"%s\".", PROPERTY_GRAPH_NAME)); Preconditions.checkState(null == getTemplateConfiguration(), "You may only have one template configuration and one exists already."); final Map<Object, Object> map = ConfigurationConverter.getMap(config); final Vertex v = graph.addVertex(); v.property(PROPERTY_TEMPLATE, true); map.forEach((key, value) -> v.property((String) key, value)); graph.tx().commit(); }
From source file:org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.java
/** * Sanitize all unwanted configuration properties to avoid leaking of sensitive * information.//from w ww .ja v a2s. c o m * @param prefix the property prefix * @param map the source map * @return the sanitized map */ @SuppressWarnings("unchecked") private Map<String, Object> sanitize(String prefix, Map<String, Object> map) { map.forEach((key, value) -> { String qualifiedKey = (prefix.isEmpty() ? prefix : prefix + ".") + key; if (value instanceof Map) { map.put(key, sanitize(qualifiedKey, (Map<String, Object>) value)); } else if (value instanceof List) { map.put(key, sanitize(qualifiedKey, (List<Object>) value)); } else { value = this.sanitizer.sanitize(key, value); value = this.sanitizer.sanitize(qualifiedKey, value); map.put(key, value); } }); return map; }