List of usage examples for java.util Set forEach
default void forEach(Consumer<? super T> action)
From source file:com.wrmsr.wava.TestWhatever.java
private static void showBasics(Name fname, BasicSet basics, boolean drawDoms) throws Exception { BasicDominatorInfo dt = BasicDominatorInfo.build(basics); BasicLoopInfo li = BasicLoopInfo.build(basics, dt); Function<Name, String> nameMangler = n -> n.get().replace('$', '_'); StringBuilder sb = new StringBuilder(); sb.append("digraph G {\n"); sb.append("labelloc=\"t\";"); sb.append(String.format("label=\"%s (%d)\";", fname.get(), basics.size())); List<Name> order = basics.basics().stream() .sorted((l, r) -> Integer.compare(l.getIndex().getAsInt(), r.getIndex().getAsInt())) .map(Basic::getName).collect(toImmutableList()); for (Name name : order) { Basic basic = basics.get(name);/*from w ww . j a va 2 s. c o m*/ Name idom = dt.getImmediateDominator(basic.getName()); Set<Name> domFront = dt.getDominanceFrontiers().get(basic.getName()); boolean isLoop = li.isLoop(basic.getName()); boolean isIf = !isLoop && basic.getAllTargets().size() == 2; // FIXME WRONG 1035 boolean isSingle = basics.getInputs(basic).size() == 1 && basic.getAllTargets().size() == 1; String nodeStyle = isLoop ? "fillcolor=blue,style=filled" : isIf ? "fillcolor=green,style=filled" : isSingle ? "fillcolor=orange,style=filled" : ""; int totalSize = basic.getBody().stream().mapToInt(Analyses::getChildCount).sum(); sb.append(String.format("%s [label=\"%s: %d, %d, %d\",%s];\n", nameMangler.apply(basic.getName()), basic.getName().get(), basic.getIndex().getAsInt(), basic.getBody().size(), totalSize, nodeStyle)); if (drawDoms) { if (idom != null) { sb.append(String.format("%s -> %s [color=red];\n", nameMangler.apply(idom), nameMangler.apply(basic.getName()))); } domFront.forEach(df -> sb.append(String.format("%s -> %s [color=red,style=dotted];\n", nameMangler.apply(basic.getName()), nameMangler.apply(df)))); } Name loopParent = li.getLoopParent(name); if (loopParent != null) { sb.append(String.format("%s -> %s [color=blue,style=dotted];\n", nameMangler.apply(loopParent), nameMangler.apply(basic.getName()))); } basic.getAllTargets().forEach(output -> { String edgeStyle = li.getBackEdges().containsEntry(output, basic.getName()) ? "fillcolor=blue" : ""; sb.append(String.format("%s -> %s [%s];\n", nameMangler.apply(basic.getName()), nameMangler.apply(output), edgeStyle)); }); } Basics.TERMINAL_NAMES .forEach(n -> sb.append(String.format("%s [label=\"%s\"];\n", nameMangler.apply(n), n.get()))); sb.append("}\n"); showGraph(sb.toString()); }
From source file:$.AppUiTopovMessageHandler.java
private Highlights fromLinks(Set<Link> links, DeviceId devId) { DemoLinkMap linkMap = new DemoLinkMap(); if (links != null) { log.debug("Processing {} links", links.size()); links.forEach(linkMap::add); } else {//from ww w . ja v a2 s . co m log.debug("No egress links found for device {}", devId); } Highlights highlights = new Highlights(); for (DemoLink dlink : linkMap.biLinks()) { dlink.makeImportant().setLabel("Yo!"); highlights.add(dlink.highlight(null)); } return highlights; }
From source file:com.adobe.ags.curly.controller.ActionRunner.java
private void applyVariables(Map<String, String> variables) { Set<String> variableTokens = ActionUtils.getVariableNames(action); variableTokens.forEach((String originalName) -> { String[] parts = originalName.split("\\|"); String var = parts[0]; String replaceVar = Pattern.quote("${" + originalName + "}"); String replace = variables.get(var) == null ? "" : variables.get(var); URL = URL.replaceAll(replaceVar, Matcher.quoteReplacement(replace)); putFile = putFile.replaceAll(replaceVar, Matcher.quoteReplacement(replace)); });/*from w w w . j a va 2s. c o m*/ applyMultiVariablesToMap(variables, postVariables); applyMultiVariablesToMap(variables, getVariables); applyVariablesToMap(variables, requestHeaders); }
From source file:org.apache.solr.metrics.reporters.solr.SolrReporter.java
@Override public void report() { String url = urlProvider.get(); // if null then suppress reporting if (url == null) { return;/*from w w w . j a va 2 s. co m*/ } SolrClient solr; if (cloudClient) { solr = clientCache.getCloudSolrClient(url); } else { solr = clientCache.getHttpSolrClient(url); } UpdateRequest req = new UpdateRequest(handler); req.setParams(params); compiledReports.forEach(report -> { Set<String> registryNames = metricManager.registryNames(report.registryPattern); registryNames.forEach(registryName -> { String label = report.label; if (label != null && label.indexOf('$') != -1) { // label with back-references Matcher m = report.registryPattern.matcher(registryName); label = m.replaceFirst(label); } final String effectiveLabel = label; String group = report.group; if (group.indexOf('$') != -1) { // group with back-references Matcher m = report.registryPattern.matcher(registryName); group = m.replaceFirst(group); } final String effectiveGroup = group; MetricUtils.toSolrInputDocuments(metricManager.registry(registryName), Collections.singletonList(report.filter), MetricFilter.ALL, MetricUtils.PropertyFilter.ALL, skipHistograms, skipAggregateValues, compact, metadata, doc -> { doc.setField(REGISTRY_ID, registryName); doc.setField(GROUP_ID, effectiveGroup); if (effectiveLabel != null) { doc.setField(LABEL_ID, effectiveLabel); } req.add(doc); }); }); }); // if no docs added then don't send a report if (req.getDocuments() == null || req.getDocuments().isEmpty()) { return; } try { //log.info("%%% sending to " + url + ": " + req.getParams()); solr.request(req); } catch (Exception e) { log.debug("Error sending metric report", e.toString()); } }
From source file:nu.yona.server.device.service.DeviceService.java
private void removeDuplicateDefaultDevice(User userEntity, UserDevice requestingDevice, UserDevice deviceToBeRemoved) {/* w ww. ja v a 2 s . c om*/ Set<Activity> activitiesOnDevice = activityRepository .findByDeviceAnonymized(deviceToBeRemoved.getDeviceAnonymized()); activitiesOnDevice.forEach(a -> a.setDeviceAnonymized(requestingDevice.getDeviceAnonymized())); deleteDeviceWithoutBuddyNotification(userEntity, deviceToBeRemoved); }
From source file:com.grepcurl.random.BaseGenerator.java
public String randomWords(int count) { Validate.isTrue(count > 0);/*w w w . j a v a 2s . co m*/ if (_dictionary == null) { _loadDictionary(); } Set<String> words = choose(_dictionary, count); StringBuilder s = new StringBuilder(); words.forEach(word -> s.append(word).append(" ")); return s.toString().trim(); }
From source file:org.dllearner.algorithms.qtl.experiments.BenchmarkDescriptionGenerator.java
private void exportGraph(Query query, File file) { mxGraph graph = new mxGraph(); Object parent = graph.getDefaultParent(); // Adds cells to the model in a single step graph.getModel().beginUpdate();//from w w w.j ava 2 s . c o m try { Set<Triple> tps = utils.extractTriplePattern(query); Map<Node, Object> mapping = new HashMap<>(); tps.forEach(tp -> { Object val1 = mapping.putIfAbsent(tp.getSubject(), graph.insertVertex(parent, null, tp.getSubject().toString(query.getPrefixMapping()), 20, 20, 40, 30)); Object val2 = mapping.putIfAbsent(tp.getObject(), graph.insertVertex(parent, null, tp.getObject().toString(query.getPrefixMapping()), 20, 20, 40, 30)); }); tps.forEach(tp -> { graph.insertEdge(parent, null, tp.getPredicate().toString(query.getPrefixMapping()), mapping.get(tp.getSubject()), mapping.get(tp.getObject())); }); } finally { // Updates the display graph.getModel().endUpdate(); } mxGraphComponent graphComponent = new mxGraphComponent(graph); // positioning via jgraphx layouts // mxHierarchicalLayout layout = new mxHierarchicalLayout(graph); // layout.setParallelEdgeSpacing(20d); // layout.setIntraCellSpacing(40d); mxGraphLayout layout = new mxOrthogonalLayout(graph); layout.execute(graph.getDefaultParent()); Map<String, Object> edgeStyle = new HashMap<String, Object>(); //edgeStyle.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL); edgeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR); edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC); edgeStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000"); edgeStyle.put(mxConstants.STYLE_FONTCOLOR, "#000000"); edgeStyle.put(mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, "#ffffff"); Map<String, Object> nodeStyle = new HashMap<>(); nodeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE); nodeStyle.put(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_BOTTOM); mxStylesheet stylesheet = new mxStylesheet(); stylesheet.setDefaultEdgeStyle(edgeStyle); stylesheet.setDefaultVertexStyle(nodeStyle); graph.setStylesheet(stylesheet); // JFrame frame = new JFrame(); // frame.getContentPane().add(new mxGraphComponent(adapter)); // frame.pack(); // frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // frame.setVisible(true); BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); try { FileOutputStream outputStream = new FileOutputStream(file); mxPngImageEncoder encoder = new mxPngImageEncoder(outputStream, param); if (image != null) { encoder.encode(image); } outputStream.close(); // ImageIO.write(image, "PNG", file); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.codice.ddf.security.sts.claims.property.UsersAttributesFileClaimsHandler.java
@Override public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claimCollection, ClaimsParameters claimsParameters) { ProcessedClaimCollection claimsColl = new ProcessedClaimCollection(); Principal principal = claimsParameters.getPrincipal(); if (principal == null) { return claimsColl; }// w w w. j a v a2s .c o m String name; if (principal instanceof X500Principal) { name = SubjectUtils.getCommonName((X500Principal) principal); } else { name = principal.getName(); } Map<String, Set<String>> userMap = json.get(name); if (userMap == null) { userMap = attemptToFindAMatchingRegexFormatUserEntry(principal, json); } if (userMap == null) { return claimsColl; } for (Claim claim : claimCollection) { Set<String> attributeValue = userMap.get(claim.getClaimType().toString()); ProcessedClaim c = new ProcessedClaim(); c.setClaimType(claim.getClaimType()); c.setPrincipal(principal); if (attributeValue != null) { attributeValue.forEach(c::addValue); claimsColl.add(c); } } return claimsColl; }
From source file:com.netflix.spinnaker.clouddriver.cloudfoundry.client.ServiceInstances.java
public ServiceInstanceResponse unshareServiceInstance(@Nullable String serviceInstanceName, @Nullable Set<String> unshareFromRegions) { Set<CloudFoundrySpace> unshareFromSpaces = vetUnshareServiceArgumentsAndGetSharingSpaces( serviceInstanceName, unshareFromRegions); unshareFromSpaces.forEach(space -> Optional .ofNullable(spaces.getServiceInstanceByNameAndSpace(serviceInstanceName, space)) .map(si -> safelyCall(() -> api.unshareServiceInstanceFromSpaceId(si.getId(), space.getId())))); return new ServiceInstanceResponse().setServiceInstanceName(serviceInstanceName).setType(UNSHARE) .setState(SUCCEEDED);/*from w w w . ja va 2s . c om*/ }