List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:Main.java
@SuppressWarnings("unchecked") static public LinkedHashMap<Object, Comparable> sortHashMapByValues(HashMap<Object, Comparable> passedMap) { ArrayList mapKeys = new ArrayList(passedMap.keySet()); ArrayList mapValues = new ArrayList(passedMap.values()); Collections.sort(mapValues);/* w ww.j a v a2 s .c o m*/ Collections.sort(mapKeys); LinkedHashMap<Object, Comparable> sortedMap = new LinkedHashMap<Object, Comparable>(); Iterator<Comparable> valueIt = mapValues.iterator(); while (valueIt.hasNext()) { Comparable val = valueIt.next(); Iterator keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { Object key = keyIt.next(); Comparable comp = passedMap.get(key); if (comp.equals(val)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put(key, val); break; } } } return sortedMap; }
From source file:com.jrummyapps.busybox.utils.Utils.java
/** * Get a list of supported binaries for the given ABI. * * @param abi/*from w w w .ja va 2 s.c o m*/ * the {@link ABI} to filter * @return a list of binaries from the assets in this APK file. */ public static ArrayList<BinaryInfo> getBinariesFromAssets(ABI abi) { ArrayList<BinaryInfo> binaries = getBinariesFromAssets(); String flavor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH ? "pie" : "nopie"; for (Iterator<BinaryInfo> iterator = binaries.iterator(); iterator.hasNext();) { BinaryInfo binaryInfo = iterator.next(); if (!TextUtils.equals(binaryInfo.abi, abi.base) || !TextUtils.equals(binaryInfo.flavor, flavor)) { iterator.remove(); } } return binaries; }
From source file:Main.java
/** * Searches parent node for matching child nodes. * * @param node The parent node/* w ww . j ava 2s. c o m*/ * @param nodeName The child node's element name * @return A list of matching child Nodes */ public static Iterator getNodes(Node node, String nodeName) { ArrayList nodes = new ArrayList(); NodeList nl = node.getChildNodes(); int nll = nl.getLength(); for (int i = 0; i < nll; i++) { Node n = nl.item(i); if (n.getNodeName().equals(nodeName)) { nodes.add(n); } } return nodes.iterator(); }
From source file:Utils.java
public static Element[] getElements(Document document, Element parent) { if (parent == null) { return new Element[] {}; }/*from w w w.jav a 2s.c o m*/ NodeList nl = parent.getChildNodes(); ArrayList al = new ArrayList(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { al.add((Element) nl.item(i)); } } Element[] ret = new Element[al.size()]; Iterator it = al.iterator(); int i = 0; while (it.hasNext()) { ret[i] = (Element) it.next(); i++; } return ret; }
From source file:Main.java
public static Iterator getElementsByTagName(Element element, String tag) { ArrayList<Element> children = new ArrayList<Element>(); if (element != null && tag != null) { NodeList nodes = element.getElementsByTagName(tag); for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); children.add((Element) child); }/*from ww w . jav a 2 s.co m*/ } return children.iterator(); }
From source file:ProcessLauncher.java
private static String[] toStringArray(ArrayList list) { String[] result = new String[list.size()]; Iterator iter = list.iterator(); int arrayIndex = 0; while (iter.hasNext()) { result[arrayIndex++] = iter.next().toString(); }/*from ww w .java 2 s . c o m*/ return result; }
From source file:Main.java
public static String generateBgsid(HashMap hashmap) { StringBuffer stringbuffer = new StringBuffer(); ArrayList arraylist = new ArrayList(); for (Iterator iterator = hashmap.entrySet().iterator(); iterator.hasNext(); arraylist .add(((java.util.Map.Entry) iterator.next()).getKey())) { }/*from w ww. j av a 2 s . c o m*/ Collections.sort(arraylist, String.CASE_INSENSITIVE_ORDER); for (Iterator iterator1 = arraylist.iterator(); iterator1.hasNext(); stringbuffer .append((String) hashmap.get((String) iterator1.next()))) { } stringbuffer.append("c18c24046606b2e084edd37f9fe9f94d"); return md5(stringbuffer.toString()); }
From source file:FileUtil.java
/** * Tests if the given File contains the given Search String * * @param aFileName A files name * @param aSearchString the String to search for * @param caseInSensitiveSearch If false the Search is casesensitive * @return true if found in the file otherwise false *///from w ww . ja v a 2s .c o m public static boolean fileContains(String aFileName, String aSearchString, boolean caseInSensitiveSearch) { boolean result = false; String searchString = caseInSensitiveSearch ? aSearchString.toLowerCase() : aSearchString; ArrayList fileContent = new ArrayList(); try { fileContent = getFileContent(aFileName); } catch (IOException e) { // TODO handle Exception e.printStackTrace(); } Iterator linesIter = fileContent.iterator(); while (linesIter.hasNext()) { String currentline = (String) linesIter.next(); if (caseInSensitiveSearch) { currentline = currentline.toLowerCase(); } if (currentline.indexOf(searchString) > -1) { result = true; break; } } return result; }
From source file:gov.nih.nci.lmp.mimGpml.CommonHelper.java
/** * Receives the collection containing errors found during validation and * print the errors to the console./*ww w .jav a 2 s. co m*/ * * @param validationErrors * The validation errors. */ public static void printErrors(ArrayList<XmlError> validationErrors) { Iterator<XmlError> iter = validationErrors.iterator(); while (iter.hasNext()) { Logger.log.error(">> " + iter.next().toString() + "\n"); } }
From source file:Main.java
public static XPathExpression newXPath(String xpath, final Map<String, String> namespaces) throws XPathExpressionException { final XPath xp = newXPathFactory().newXPath(); xp.setNamespaceContext(new NamespaceContext() { @Override/*from w ww. j av a 2 s . c om*/ public String getNamespaceURI(String prefix) { return namespaces != null ? namespaces.get(prefix) : null; } @Override public String getPrefix(String namespaceURI) { if (namespaces == null) { return null; } else { final Iterator i = getPrefixes(namespaceURI); if (i.hasNext()) { return (String) i.next(); } else { return null; } } } @Override public Iterator getPrefixes(String namespaceURI) { if (namespaces == null) { return null; } else { ArrayList<String> list = new ArrayList<String>(); for (Map.Entry<String, String> entry : namespaces.entrySet()) { if (entry.getValue().equals(namespaceURI)) { list.add(entry.getKey()); } } return list.iterator(); } } }); return xp.compile(xpath); }