List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:cool.pandora.modeller.ui.handlers.iiif.PatchCanvasHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.canvaspatched"); final DefaultBag bag = bagView.getBag(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); final URI resourceContainerURI = IIIFObjectURI.getResourceContainerURI(map); final URI canvasContainerURI = IIIFObjectURI.getCanvasContainerURI(map); final URI ListContainerURI = IIIFObjectURI.getListContainerURI(map); final ResourceList canvasList = new ResourceList(canvasContainerURI); final ArrayList<String> canvasesList = canvasList.getResourceList(); final ResourceList resourceList = new ResourceList(resourceContainerURI); final ArrayList<String> resourcesList = resourceList.getResourceList(); final ResourceList listList = new ResourceList(ListContainerURI); final ArrayList<String> listsList = listList.getResourceList(); final Iterator<String> i1 = canvasesList.iterator(); final Iterator<String> i2 = resourcesList.iterator(); final Iterator<String> i3 = canvasesList.iterator(); final Iterator<String> i4 = listsList.iterator(); final Map<String, String> canvasResourceMap = new LinkedHashMap<>(); final Map<String, String> canvasListMap = new LinkedHashMap<>(); while (i1.hasNext() && i2.hasNext()) { canvasResourceMap.put(i1.next(), i2.next()); }// w w w. j a va 2 s.c om while (i3.hasNext() && i4.hasNext()) { canvasListMap.put(i3.next(), i4.next()); } InputStream rdfBody; for (final String canvasURI : canvasesList) { rdfBody = getCanvasMetadata(canvasResourceMap.get(canvasURI), canvasListMap.get(canvasURI)); final URI destinationURI = URI.create(canvasURI); try { ModellerClient.doPatch(destinationURI, rdfBody); ApplicationContextUtil.addConsoleMessage(message + " " + destinationURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } bagView.getControl().invalidate(); }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static void processChildNodes(ArrayList<Node> nodeList, StringBuffer sb, int indentLevel, boolean doText, boolean withFormatting, boolean trim, String appendToCRLF, String contextPath, int projectId) { Iterator nodeI = nodeList.iterator(); while (nodeI.hasNext()) { Node n = (Node) nodeI.next(); if (n != null) { if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) { if (doText) { String value = n.getNodeValue(); // Escaped characters value = StringUtils.replace(value, "*", "\\*"); value = StringUtils.replace(value, "#", "\\#"); value = StringUtils.replace(value, "=", "\\="); value = StringUtils.replace(value, "|", "\\|"); value = StringUtils.replace(value, "[", "\\{"); value = StringUtils.replace(value, "]", "\\}"); if (trim && !nodeI.hasNext()) { // If within a cell, make sure returns include the cell value // String value = (appendToCRLF.length() > 0 ? StringUtils.replace(n.getNodeValue(), CRLF, CRLF + appendToCRLF) : n.getNodeValue()); LOG.trace(" <text:trim>"); // Output the value, trim is required sb.append(StringUtils.fromHtmlValue(value.trim())); } else { // If within a cell, make sure returns include the cell value if (appendToCRLF.length() > 0 && (hasParentNodeType(n, "th") || hasParentNodeType(n, "td")) && value.trim().length() == 0) { // This is an empty value... check to see if the previous line has content or not before appending a new line } else { LOG.trace(" <text>"); sb.append(StringUtils.fromHtmlValue((appendToCRLF.length() > 0 ? StringUtils.replace(value, CRLF, CRLF + appendToCRLF) : value))); }//from ww w . jav a 2 s . c o m } } } else if (n.getNodeType() == Node.ELEMENT_NODE) { Element element = ((Element) n); String tag = element.getTagName(); LOG.trace(tag); if ("h1".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("= ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" =").append(CRLF + appendToCRLF); } else if ("h2".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ==").append(CRLF + appendToCRLF); } else if ("h3".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("=== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ===").append(CRLF + appendToCRLF); } else if ("h4".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("==== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ====").append(CRLF + appendToCRLF); } else if ("h5".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("===== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" =====").append(CRLF + appendToCRLF); } else if ("h6".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("====== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ======").append(CRLF + appendToCRLF); } else if ("p".equals(tag) || "div".equals(tag)) { if (n.getChildNodes().getLength() > 0 && (hasTextContent(n) || hasImageNodes(n.getChildNodes()))) { // If this contains a Table, UL, OL, or object skip everything else to get there ArrayList<Node> subNodes = new ArrayList<Node>(); getNodes(n.getChildNodes(), subNodes, new String[] { "table", "ul", "ol", "object" }, false); if (subNodes.size() > 0) { LOG.trace(" nonTextNodes - yes"); processChildNodes(subNodes, sb, indentLevel, true, true, false, appendToCRLF, contextPath, projectId); } else { LOG.trace(" nonTextNodes - no"); startOnNewLine(sb, appendToCRLF); processChildNodes(getNodeList(n), sb, indentLevel, true, true, false, appendToCRLF, contextPath, projectId); } } } else if ("strong".equals(tag) || "b".equals(tag)) { if (n.getChildNodes().getLength() > 0) { if ("".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, false, appendToCRLF, contextPath, projectId); } else { if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, false, appendToCRLF, contextPath, projectId); } else { if (withFormatting) { sb.append("'''"); } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, false, appendToCRLF, contextPath, projectId); if (withFormatting) { sb.append("'''"); } } } } } else if ("em".equals(tag) || "i".equals(tag)) { if (n.getChildNodes().getLength() > 0) { if ("".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, trim, appendToCRLF, contextPath, projectId); } else { if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); } else { if (withFormatting) { sb.append("''"); } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); if (withFormatting) { sb.append("''"); } } } } } else if ("span".equals(tag)) { if (n.getChildNodes().getLength() > 0 && !"".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { if (element.hasAttribute("style")) { String value = element.getAttribute("style"); if (withFormatting) { if (value.contains("underline")) { sb.append("__"); } if (value.contains("line-through")) { sb.append("<s>"); } if (value.contains("bold")) { sb.append("'''"); } if (value.contains("italic")) { sb.append("''"); } } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); if (withFormatting) { if (value.contains("italic")) { sb.append("''"); } if (value.contains("bold")) { sb.append("'''"); } if (value.contains("line-through")) { sb.append("</s>"); } if (value.contains("underline")) { sb.append("__"); } } } else { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); } } } else if ("ul".equals(tag) || "ol".equals(tag) || "dl".equals(tag)) { ++indentLevel; if (indentLevel == 1) { if (appendToCRLF.length() == 0) { startOnNewLine(sb, appendToCRLF); } else { // Something\n // ! // !* Item 1 // !* Item 2 if (!sb.toString().endsWith("|") && !sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("ul newline CRLF"); sb.append(CRLF + appendToCRLF); } } } if (indentLevel > 1 && !sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("ul indent CRLF"); sb.append(CRLF + appendToCRLF); } processChildNodes(getNodeList(n), sb, indentLevel, false, false, trim, appendToCRLF, contextPath, projectId); --indentLevel; } else if ("li".equals(tag)) { String parentTag = ((Element) element.getParentNode()).getTagName(); for (int counter = 0; counter < indentLevel; counter++) { if ("ul".equals(parentTag)) { sb.append("*"); } else if ("ol".equals(parentTag)) { sb.append("#"); } } sb.append(" "); processChildNodes(getNodeList(n), sb, indentLevel, true, false, true, appendToCRLF, contextPath, projectId); if (!sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("li CRLF"); sb.append(CRLF + appendToCRLF); } } else if ("dt".equals(tag) || "dd".equals(tag)) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, trim, appendToCRLF, contextPath, projectId); if (!sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("dt CRLF"); sb.append(CRLF + appendToCRLF); } } else if ("pre".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("<pre>"); processChildNodes(getNodeList(n), sb, indentLevel, true, true, trim, appendToCRLF, contextPath, projectId); sb.append("</pre>"); if (nodeI.hasNext()) { sb.append(CRLF + appendToCRLF); sb.append(CRLF + appendToCRLF); } } else if ("code".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("<code>"); processChildNodes(getNodeList(n), sb, indentLevel, true, true, trim, appendToCRLF, contextPath, projectId); sb.append("</code>"); if (nodeI.hasNext()) { sb.append(CRLF + appendToCRLF); sb.append(CRLF + appendToCRLF); } } else if ("br".equals(tag)) { LOG.trace("br CRLF"); sb.append(CRLF + appendToCRLF); } else if ("table".equals(tag)) { // Always start a table on a new line startOnNewLine(sb, appendToCRLF); processTable(n.getChildNodes(), sb, 0, false, false, contextPath, projectId, 0); //if (nodeI.hasNext()) { // sb.append(CRLF); //} } else if ("form".equals(tag)) { // Always start a form on a new line startOnNewLine(sb, appendToCRLF); CustomForm form = processForm(n); convertFormToWiki(form, sb); } else if ("a".equals(tag)) { // Determine if the link is around text or around an image if (n.getChildNodes().getLength() > 0 && hasImageNodes(n.getChildNodes())) { // The link is around an image LOG.debug("Processing link as an image"); // Get the img tag and pass to processImage... ArrayList<Node> subNodes = new ArrayList<Node>(); getNodes(n.getChildNodes(), subNodes, new String[] { "img" }, false); processImage(sb, subNodes.get(0), (Element) subNodes.get(0), appendToCRLF, contextPath, projectId); } else { // The link is around text processLink(sb, element, appendToCRLF, contextPath, projectId); } } else if ("img".equals(tag)) { processImage(sb, n, element, appendToCRLF, contextPath, projectId); } else if ("object".equals(tag)) { startOnNewLine(sb, appendToCRLF); processVideo(sb, n, element, appendToCRLF, contextPath); } else { processChildNodes(getNodeList(n), sb, indentLevel, false, true, trim, appendToCRLF, contextPath, projectId); } } } } }
From source file:net.ontopia.topicmaps.utils.MergeUtils.java
private static boolean equals(TMObjectIF obj1, TMObjectIF obj2) { // can't be topics, or we wouldn't be here if (obj1 instanceof AssociationIF && obj2 instanceof AssociationIF) { AssociationIF a1 = (AssociationIF) obj1; AssociationIF a2 = (AssociationIF) obj2; if (a1.getType() == a2.getType() && a1.getRoles().size() == a2.getRoles().size() && a1.getScope().equals(a2.getScope())) { ArrayList<AssociationRoleIF> roles2 = new ArrayList<AssociationRoleIF>(a2.getRoles()); Iterator<AssociationRoleIF> it1 = a1.getRoles().iterator(); while (it1.hasNext()) { AssociationRoleIF role1 = it1.next(); Iterator<AssociationRoleIF> it2 = roles2.iterator(); boolean found = false; while (it2.hasNext()) { AssociationRoleIF role2 = it2.next(); if (role2.getPlayer() == role1.getPlayer() && role1.getType() == role2.getType()) { roles2.remove(role2); found = true;/*from w w w. j av a2 s . c o m*/ break; } } if (!found) break; } return roles2.isEmpty(); } } else if (obj1 instanceof TopicNameIF && obj2 instanceof TopicNameIF) { TopicNameIF bn1 = (TopicNameIF) obj1; TopicNameIF bn2 = (TopicNameIF) obj2; return (bn1.getTopic().equals(bn2.getTopic()) && sameAs(bn1.getValue(), bn2.getValue()) && sameAs(bn1.getType(), bn2.getType()) && sameAs(bn1.getScope(), bn2.getScope())); } else if (obj1 instanceof OccurrenceIF && obj2 instanceof OccurrenceIF) { OccurrenceIF occ1 = (OccurrenceIF) obj1; OccurrenceIF occ2 = (OccurrenceIF) obj2; return (occ1.getTopic().equals(occ2.getTopic()) && sameAs(occ1.getValue(), occ2.getValue()) && sameAs(occ1.getDataType(), occ2.getDataType()) && sameAs(occ1.getType(), occ2.getType()) && sameAs(occ1.getScope(), occ2.getScope())); } return false; }
From source file:com.example.android.uamp.model.RemoteJSONSource.java
@Override public Iterator<MediaMetadataCompat> iterator() { try {// ww w . j a va 2 s. c o m int slashPos = CATALOG_URL.lastIndexOf('/'); String path = CATALOG_URL.substring(0, slashPos + 1); JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL); ArrayList<MediaMetadataCompat> tracks = new ArrayList<>(); if (jsonObj != null) { JSONArray jsonTracks = jsonObj.getJSONArray(JSON_MUSIC); if (jsonTracks != null) { for (int j = 0; j < jsonTracks.length(); j++) { tracks.add(buildFromJSON(jsonTracks.getJSONObject(j), path)); } } } return tracks.iterator(); } catch (JSONException e) { LogHelper.e(TAG, e, "Could not retrieve music list"); throw new RuntimeException("Could not retrieve music list", e); } }
From source file:com.linkedin.pinot.integration.tests.Pql2CompilerTest.java
private void displayFilterDifference(List<Integer> leftIds, List<Integer> rightIds, FilterQueryMap leftSubQueries, FilterQueryMap rightSubQueries) { ArrayList<Integer> leftIdsCopy = new ArrayList<>(leftIds); ArrayList<Integer> rightIdsCopy = new ArrayList<>(rightIds); Iterator<Integer> leftIterator = leftIdsCopy.iterator(); while (leftIterator.hasNext()) { Integer leftId = leftIterator.next(); Iterator<Integer> rightIterator = rightIdsCopy.iterator(); while (rightIterator.hasNext()) { Integer rightId = rightIterator.next(); if (filterQueryIsEquivalent(Collections.singletonList(leftId), Collections.singletonList(rightId), leftSubQueries, rightSubQueries)) { leftIterator.remove();/*from w ww.j av a2 s .com*/ rightIterator.remove(); break; } } } if (!leftIdsCopy.isEmpty()) { System.out.println(" ----- "); for (Integer leftId : leftIdsCopy) { System.out.println("leftSubQuery = " + leftSubQueries.getFilterQueryMap().get(leftId)); } for (Integer rightId : rightIdsCopy) { System.out.println("rightSubQuery = " + rightSubQueries.getFilterQueryMap().get(rightId)); } System.out.println(" ----- "); if (leftIdsCopy.size() != 1 || rightIdsCopy.size() != 1) { System.out.println("MORE THAN ONE DIFFERENCE!"); } else { int leftId = leftIdsCopy.get(0); int rightId = rightIdsCopy.get(0); FilterQuery left = leftSubQueries.getFilterQueryMap().get(leftId); FilterQuery right = rightSubQueries.getFilterQueryMap().get(rightId); ArrayList<Integer> leftChildrenIdsCopy = new ArrayList<>(left.getNestedFilterQueryIds()); ArrayList<Integer> rightChildrenIdsCopy = new ArrayList<>(right.getNestedFilterQueryIds()); Iterator<Integer> leftChildrenIterator = leftChildrenIdsCopy.iterator(); while (leftChildrenIterator.hasNext()) { Integer leftChildrenId = leftChildrenIterator.next(); Iterator<Integer> rightChildrenIterator = rightChildrenIdsCopy.iterator(); while (rightChildrenIterator.hasNext()) { Integer rightChildrenId = rightChildrenIterator.next(); if (filterQueryIsEquivalent(Collections.singletonList(leftChildrenId), Collections.singletonList(rightChildrenId), leftSubQueries, rightSubQueries)) { leftChildrenIterator.remove(); rightChildrenIterator.remove(); break; } } } displayFilterDifference(leftChildrenIdsCopy, rightChildrenIdsCopy, leftSubQueries, rightSubQueries); } } }
From source file:dom.rootlocus.utils.Utils.java
public Complex[] getRootsSimplified(Complex[] r) { // int pCompRoots = countComplexPairRoots(r); ArrayList<Complex> sr = new ArrayList<>(); for (int i = 0; i < r.length; i++) { if (r[i].getImaginary() == 0) { sr.add(r[i]);/*ww w. ja v a 2s . c om*/ } else { Iterator it = sr.iterator(); int count = 0; while (it.hasNext()) { Complex c = (Complex) it.next(); double Re = new BigDecimal(c.getReal()).setScale(4, RoundingMode.HALF_UP).doubleValue(); double Img = new BigDecimal(c.getImaginary()).setScale(4, RoundingMode.HALF_UP).doubleValue(); double rootRe = new BigDecimal(r[i].getReal()).setScale(4, RoundingMode.HALF_UP).doubleValue(); double rootImg = new BigDecimal(r[i].getImaginary()).setScale(4, RoundingMode.HALF_UP) .doubleValue(); if (Re == rootRe && (Img == rootImg || Img == -rootImg)) { count++; break; } } if (count == 0) { sr.add(r[i]); } } } return sr.toArray(new Complex[sr.size()]); }
From source file:com.sec.ose.osi.util.Property.java
public Iterator<String> getKeys() { ArrayList<String> list = new ArrayList<String>(); Iterator<Object> itr = this.mProperty.keySet().iterator(); if (itr == null) return null; while (itr.hasNext()) { list.add(itr.next().toString()); }// w ww. ja v a2 s . co m return list.iterator(); }
From source file:TreeNode.java
/** * Return an Iterator over all children of this node that have the * specified name. If there are no such children, an empty Iterator * is returned./*from w ww. j ava 2 s. co m*/ * * @param name Name used to select children */ public Iterator findChildren(String name) { if (children == null) return (Collections.EMPTY_LIST.iterator()); ArrayList results = new ArrayList(); Iterator items = children.iterator(); while (items.hasNext()) { TreeNode item = (TreeNode) items.next(); if (name.equals(item.getName())) results.add(item); } return (results.iterator()); }
From source file:com.polyvi.xface.extension.capture.MediaType.java
/** * capture JS./*from ww w. ja v a 2s . c o m*/ * * @param app app * @param jsCallback XJsCallback */ public void sendbackResult(XIWebContext webContext, XCallbackContext callbackCtx) { ArrayList<JSONObject> list = mResultMap.get(callbackCtx); Iterator<JSONObject> itor = list.iterator(); JSONArray resultArray = new JSONArray(); while (itor.hasNext()) { resultArray.put(itor.next()); } callbackCtx.success(resultArray); }
From source file:ca.sfu.federation.viewer.propertysheet.LinePropertySheet.java
/** * Build an Update Method user input panel. * @return Panel./*from w w w. j a va 2 s . c om*/ */ private JPanel buildUpdateMethodInputsPanel() { // init JPanel panel = new JPanel(); // build panel InputTable inputTable = this.target.getInputTable(); ArrayList keys = (ArrayList) inputTable.getInputKeys(); if (keys.size() > 0) { panel.setLayout(new RiverLayout()); boolean first = true; Iterator e = keys.iterator(); while (e.hasNext()) { String key = (String) e.next(); if (first) { panel.add("p left", new JLabel(key)); panel.add("tab hfill", new InputTextField(inputTable, key)); first = false; } else { panel.add("br", new JLabel(key)); panel.add("tab hfill", new InputTextField(inputTable, key)); } } } // clear the scrollpane, add the new panel, validate this.jspUpdateMethodInputs.removeAll(); this.jspUpdateMethodInputs.add(panel, BorderLayout.CENTER); this.jspUpdateMethodInputs.validate(); // return result return panel; }