List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:com.pjaol.ESB.formatters.JSONFormatter.java
private JSONObject recurseMap(Map items) { JSONObject jo = new JSONObject(); Set keys = items.keySet(); Iterator i = keys.iterator(); while (i.hasNext()) { String k = (String) i.next(); Object v = items.get(k);/*ww w . ja v a2s .c o m*/ if (v instanceof NamedList) { jo.put(k, recurseNamedList((NamedList) v)); } else if (v instanceof Map) { jo.put(k, recurseMap((Map) v)); } else { jo.put(k, v); } } return jo; }
From source file:com.github.ipaas.ifw.front.directive.HtmlDirective.java
private String tagBegin(Map params) { String attrs = ""; Set<String> keys = params.keySet(); for (Iterator<String> it = keys.iterator(); it.hasNext();) { String key = it.next();/*ww w . j av a 2 s. co m*/ if (key.equals(FRAMEWORK_NAME)) { continue; } attrs += " " + key + "=\"" + params.get(key) + "\";"; } return "<html " + attrs + ">\n"; }
From source file:org.calrissian.mango.json.deser.TupleDeserializerTest.java
@Test public void testSerialization_withMetadata() throws IOException { Tuple tuple = objectMapper.readValue( "{\"key\":\"key\",\"type\":\"string\",\"value\":\"value\",\"metadata\":[{\"value\":\"metaVal\",\"type\":\"string\",\"key\":\"metaKey\"}]}", Tuple.class); assertEquals("key", tuple.getKey()); assertEquals("value", tuple.getValue()); assertEquals(1, tuple.getMetadata().size()); Set<Map.Entry<String, Object>> entrySet = tuple.getMetadata().entrySet(); assertEquals("metaKey", entrySet.iterator().next().getKey()); assertEquals("metaVal", entrySet.iterator().next().getValue()); }
From source file:com.serge.cv.ResumeTests.java
@Test public void testFind() throws Exception { Resume.ResumeBuilder resumeBuilder = new ResumeBuilder(); resumeBuilder/*from w ww. j av a2 s. co m*/ .setProfil(new Profil("name", "surname", "adress", "codePostal", 12, "officenumber", "number")); Resume resumeExpected = this.resumeDao.persist(resumeBuilder.build()); Set<Resume> resumeFound = this.resumeDao.findbyName("name"); assertEquals(resumeExpected, resumeFound.iterator().next()); }
From source file:com.puppycrawl.tools.checkstyle.checks.xpath.AttributeAxisIterator.java
/** * Constructs a <code>AttributeAxisIterator</code> for a * DetailAST element./*from w ww . jav a2 s . c o m*/ * @param aAST the DetailAST element */ public AttributeAxisIterator(DetailAST aAST) { Map props = new HashMap(); //use BeanUtils to get the properties try { props = BeanUtils.describe(aAST); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } // add attributes for the properties to a list and // set the iterator to an iterator over that list. final List attributes = new ArrayList(props.size()); final Set values = props.keySet(); for (Iterator iter = values.iterator(); iter.hasNext();) { final String name = (String) iter.next(); final String value = (String) props.get(name); attributes.add(new Attribute(aAST, name, value)); } mIter = attributes.iterator(); }
From source file:net.ontopia.topicmaps.utils.TopicMapSynchronizer.java
/** * INTERNAL: Updates the target topic in the usual way, but does not * delete associations. Instead, it registers its findings using the * AssociationTracker. It is then up to the caller to delete * unwanted associations. The general principle is that associations * are wanted as long as there is one source that wants them; the * method will therefore feel free to copy new associations from the * source. In addition, associations to topics outside the set of * topics being synchronized must be kept because they cannot be * synchronized (they belong to the topics not being synchronized). *///from w w w . j a v a2 s. c o m private static void update(TopicMapIF target, TopicIF source, DeciderIF<TMObjectIF> tfilter, DeciderIF<TMObjectIF> sfilter, AssociationTracker tracker) { TopicMapBuilderIF builder = target.getBuilder(); // find target TopicIF targett = getTopic(target, source); if (targett == null) { targett = builder.makeTopic(); log.debug("Updating new target {} with source {}", targett, source); } else { log.debug("Updating existing target {} with source {}", targett, source); } targett = copyIdentifiers(targett, source); // synchronize types Set<TopicIF> origtypes = new CompactHashSet<TopicIF>(targett.getTypes()); Iterator<TopicIF> topicIterator = source.getTypes().iterator(); while (topicIterator.hasNext()) { TopicIF stype = topicIterator.next(); TopicIF ttype = getOrCreate(target, stype); if (origtypes.contains(ttype)) origtypes.remove(ttype); else targett.addType(ttype); } topicIterator = origtypes.iterator(); while (topicIterator.hasNext()) targett.removeType(topicIterator.next()); // synchronize names Map<String, TopicNameIF> originalTopicNames = new HashMap<String, TopicNameIF>(); Iterator<TopicNameIF> topicnameIterator = targett.getTopicNames().iterator(); while (topicnameIterator.hasNext()) { TopicNameIF bn = topicnameIterator.next(); if (tfilter.ok(bn)) { log.debug(" target name included {}", bn); originalTopicNames.put(KeyGenerator.makeTopicNameKey(bn), bn); } else { log.debug(" target name excluded {}", bn); } } topicnameIterator = source.getTopicNames().iterator(); while (topicnameIterator.hasNext()) { TopicNameIF sbn = topicnameIterator.next(); if (!sfilter.ok(sbn)) { log.debug(" source name excluded {}", sbn); continue; } log.debug(" source name included {}", sbn); TopicIF ttype = getOrCreate(target, sbn.getType()); Collection<TopicIF> tscope = translateScope(target, sbn.getScope()); String key = KeyGenerator.makeScopeKey(tscope) + "$" + KeyGenerator.makeTopicKey(ttype) + "$$" + sbn.getValue(); if (originalTopicNames.containsKey(key)) { TopicNameIF tbn = originalTopicNames.get(key); update(tbn, sbn, tfilter); originalTopicNames.remove(key); } else { TopicNameIF tbn = builder.makeTopicName(targett, ttype, sbn.getValue()); addScope(tbn, tscope); addReifier(tbn, sbn.getReifier(), tfilter, sfilter, tracker); update(tbn, sbn, tfilter); log.debug(" target name added {}", tbn); } } topicnameIterator = originalTopicNames.values().iterator(); while (topicnameIterator.hasNext()) { TopicNameIF tbn = topicnameIterator.next(); log.debug(" target name removed {}", tbn); tbn.remove(); } // synchronize occurrences Map<String, OccurrenceIF> originalOccurrences = new HashMap<String, OccurrenceIF>(); Iterator<OccurrenceIF> occurrenceIterator = targett.getOccurrences().iterator(); while (occurrenceIterator.hasNext()) { OccurrenceIF occ = occurrenceIterator.next(); if (tfilter.ok(occ)) { log.debug(" target occurrence included: {}", occ); originalOccurrences.put(KeyGenerator.makeOccurrenceKey(occ), occ); } else { log.debug(" target occurrence excluded {}", occ); } } occurrenceIterator = source.getOccurrences().iterator(); while (occurrenceIterator.hasNext()) { OccurrenceIF socc = occurrenceIterator.next(); if (!sfilter.ok(socc)) { log.debug(" source occurrence excluded {}", socc); continue; } log.debug(" source occurrence included: {}", socc); TopicIF ttype = getOrCreate(target, socc.getType()); Collection<TopicIF> tscope = translateScope(target, socc.getScope()); String key = KeyGenerator.makeScopeKey(tscope) + "$" + KeyGenerator.makeTopicKey(ttype) + KeyGenerator.makeDataKey(socc); if (originalOccurrences.containsKey(key)) originalOccurrences.remove(key); else { OccurrenceIF tocc = builder.makeOccurrence(targett, ttype, ""); CopyUtils.copyOccurrenceData(tocc, socc); addScope(tocc, tscope); addReifier(tocc, socc.getReifier(), tfilter, sfilter, tracker); log.debug(" target occurrence added {}", tocc); } } occurrenceIterator = originalOccurrences.values().iterator(); while (occurrenceIterator.hasNext()) { OccurrenceIF tocc = occurrenceIterator.next(); log.debug(" target occurrence removed {}", tocc); tocc.remove(); } // synchronize associations // originals tracked by AssociationTracker, not the 'origs' set Iterator<AssociationRoleIF> roleIterator = targett.getRoles().iterator(); while (roleIterator.hasNext()) { AssociationRoleIF role = roleIterator.next(); AssociationIF assoc = role.getAssociation(); if (tfilter.ok(assoc) && tracker.isWithinSyncSet(assoc)) { log.debug(" target association included: {}", assoc); tracker.unwanted(assoc); // means: unwanted if not found in source } else { log.debug(" target association excluded {}", assoc); } } roleIterator = source.getRoles().iterator(); while (roleIterator.hasNext()) { AssociationRoleIF role = roleIterator.next(); AssociationIF sassoc = role.getAssociation(); if (!sfilter.ok(sassoc)) { log.debug(" source association excluded {}", sassoc); continue; } log.debug(" source association included: {}", sassoc); TopicIF ttype = getOrCreate(target, sassoc.getType()); Collection<TopicIF> tscope = translateScope(target, sassoc.getScope()); String key = KeyGenerator.makeTopicKey(ttype) + "$" + KeyGenerator.makeScopeKey(tscope) + "$" + makeRoleKeys(target, sassoc.getRoles()); if (!tracker.isKnown(key)) { // if the key is not known it means this association does not // exist in the target, and so we must create it AssociationIF tassoc = builder.makeAssociation(ttype); addScope(tassoc, tscope); addReifier(tassoc, sassoc.getReifier(), tfilter, sfilter, tracker); Iterator<AssociationRoleIF> it2 = sassoc.getRoles().iterator(); while (it2.hasNext()) { role = it2.next(); builder.makeAssociationRole(tassoc, getOrCreate(target, role.getType()), getOrCreate(target, role.getPlayer())); } log.debug(" target association added {}", tassoc); } tracker.wanted(key); } // run duplicate suppression DuplicateSuppressionUtils.removeDuplicates(targett); DuplicateSuppressionUtils.removeDuplicateAssociations(targett); }
From source file:com.etsy.arbiter.workflow.WorkflowGraphBuilder.java
/** * Recursively insert fork/joins for connected subcomponents of a graph * * @param vertices The set of vertices to process * @param parentGraph The parentGraph graph of these vertices * @return DirectedAcyclicGraph A new graph containing all the given vertices with appropriate fork/join pairs inserted * @throws WorkflowGraphException/*from w w w. j a v a2 s . com*/ * @throws DirectedAcyclicGraph.CycleFoundException */ private static DirectedAcyclicGraph<Action, DefaultEdge> buildComponentGraph(Set<Action> vertices, DirectedAcyclicGraph<Action, DefaultEdge> parentGraph) throws WorkflowGraphException, DirectedAcyclicGraph.CycleFoundException { DirectedAcyclicGraph<Action, DefaultEdge> subgraph = buildSubgraph(parentGraph, vertices); // Start by pulling out the vertices with no incoming edges // These can run in parallel in a fork-join Set<Action> initialNodes = new HashSet<>(); for (Action vertex : subgraph.vertexSet()) { if (subgraph.inDegreeOf(vertex) == 0) { initialNodes.add(vertex); } } DirectedAcyclicGraph<Action, DefaultEdge> result = new DirectedAcyclicGraph<>(DefaultEdge.class); if (initialNodes.isEmpty()) { // This is a very odd case, but just in case we'll fail if it happens throw new WorkflowGraphException("No nodes with inDegree = 0 found. This shouldn't happen."); } else if (initialNodes.size() == 1) { // If there is only one node, we can't put it in a fork/join // In this case we'll add just that vertex to the resulting graph Action vertex = initialNodes.iterator().next(); result.addVertex(vertex); // Remove the processed vertex so that we have new unprocessed subcomponents subgraph.removeVertex(vertex); } else { // If there are multiple nodes, insert a fork/join pair to run them in parallel Pair<Action, Action> forkJoin = addForkJoin(result); Action fork = forkJoin.getLeft(); Action join = forkJoin.getRight(); for (Action vertex : initialNodes) { result.addVertex(vertex); result.addDagEdge(fork, vertex); result.addDagEdge(vertex, join); // Remove the processed vertex so that we have new unprocessed subcomponents subgraph.removeVertex(vertex); } } // Now recursively process the graph with the processed nodes removed Triple<DirectedAcyclicGraph<Action, DefaultEdge>, Action, Action> subComponentGraphTriple = processSubcomponents( subgraph); DirectedAcyclicGraph<Action, DefaultEdge> subComponentGraph = subComponentGraphTriple.getLeft(); // Having processed the subcomponents, we attach the "last" node of the graph created here to // the "first" node of the subcomponent graph Action noIncoming = subComponentGraphTriple.getMiddle(); Action noOutgoing = null; for (Action vertex : result.vertexSet()) { if (noOutgoing == null && result.outDegreeOf(vertex) == 0) { noOutgoing = vertex; } } Graphs.addGraph(result, subComponentGraph); if (noOutgoing != null && noIncoming != null && !noOutgoing.equals(noIncoming)) { result.addDagEdge(noOutgoing, noIncoming); } return result; }
From source file:it.eng.spagobi.commons.presentation.tags.ListBIParametersTag.java
/** * Starting from the module <code>buttonsSB</code> object, * creates all buttons for the jsp list. * //from w ww .j ava 2 s. c o m * @throws JspException If any exception occurs. */ protected StringBuffer makeButton() throws JspException { StringBuffer htmlStream = new StringBuffer(); SourceBean buttonsSB = (SourceBean) _layout.getAttribute("BUTTONS"); List buttons = buttonsSB.getContainedSourceBeanAttributes(); Iterator iter = buttons.listIterator(); while (iter.hasNext()) { SourceBeanAttribute buttonSBA = (SourceBeanAttribute) iter.next(); SourceBean buttonSB = (SourceBean) buttonSBA.getValue(); List parameters = buttonSB.getAttributeAsList("PARAMETER"); HashMap paramsMap = getParametersMap(parameters, null); String img = (String) buttonSB.getAttribute("image"); String labelCode = (String) buttonSB.getAttribute("label"); String label = msgBuilder.getMessage(labelCode, "messages", httpRequest); label = StringEscapeUtils.escapeHtml(label); htmlStream.append("<form action='" + urlBuilder.getUrl(httpRequest, new HashMap()) + "' id='form" + label + "' method='POST' >\n"); htmlStream.append(" <td class=\"header-button-column-portlet-section\">\n"); Set paramsKeys = paramsMap.keySet(); Iterator iterpar = paramsKeys.iterator(); while (iterpar.hasNext()) { String paramKey = (String) iterpar.next(); String paramValue = (String) paramsMap.get(paramKey); while (paramValue.indexOf("%20") != -1) { paramValue = paramValue.replaceAll("%20", " "); } htmlStream.append( " <input type='hidden' name='" + paramKey + "' value='" + paramValue + "' /> \n"); } htmlStream.append(" <a href='javascript:document.getElementById(\"form" + label + "\").submit()'><img class=\"header-button-image-portlet-section\" title='" + label + "' alt='" + label + "' src='" + urlBuilder.getResourceLinkByTheme(httpRequest, img, currTheme) + "' /></a>\n"); htmlStream.append(" </td>\n"); htmlStream.append("</form>\n"); } return htmlStream; }
From source file:org.jasig.cas.web.support.AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapter.java
/** * This class relies on an external configuration to clean it up. It ignores the threshold data in the parent class. *//*w ww . j a v a 2 s. co m*/ public final void decrementCounts() { final Set<String> keys = this.ipMap.keySet(); for (final Iterator<String> iter = keys.iterator(); iter.hasNext();) { final String key = iter.next(); final AtomicInteger integer = this.ipMap.get(key); final int newValue = integer.decrementAndGet(); if (newValue == 0) { iter.remove(); } } }
From source file:com.intuit.tank.http.keyvalue.KeyValueRequest.java
@SuppressWarnings("rawtypes") public String getBody() { Set set = this.postData.entrySet(); Iterator iter = set.iterator(); String body = ""; while (iter.hasNext()) { try {/*from www .j av a2 s.c o m*/ Map.Entry mapEntry = (Map.Entry) iter.next(); String key = mapEntry.getKey() != null ? URLEncoder.encode((String) mapEntry.getKey(), "UTF-8") : ""; String value = mapEntry.getValue() != null ? URLEncoder.encode((String) mapEntry.getValue(), "UTF-8") : ""; if (StringUtils.isEmpty(body)) { body = key + "=" + value; } else { body = body + "&" + key + "=" + value; } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } return body; }