List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:Main.java
public static NodeList ChangeNode(NodeList listNode, ArrayList<String> arrStrCompare, String strNewValue) { ArrayList<String> arrTempList = arrStrCompare; Iterator<String> iterator = arrTempList.iterator(); while (iterator.hasNext()) { String strCompare = (String) iterator.next(); iterator.remove();/*from w ww . j a v a2 s . c om*/ for (int i = 0; i < listNode.getLength(); i++) { Node node = listNode.item(i); if (strCompare.equals(node.getNodeName())) { if (iterator.hasNext()) { node = ChangeNode(node.getChildNodes(), arrTempList, strNewValue).item(0); break; } node.setTextContent(strNewValue); break; } } } return listNode; }
From source file:Main.java
public static ArrayList<Integer> filterPoint(ArrayList<Integer> timePoints) { int lastPeriod = -1; logInConsole(timePoints);/*from w w w . jav a2s . c om*/ Iterator<Integer> it = timePoints.iterator(); while (it.hasNext()) { int tmp = it.next(); if (lastPeriod != -1 && tmp - lastPeriod < MIN_PERIOD) { it.remove(); } else { lastPeriod = tmp; } } logInConsole(timePoints); return timePoints; }
From source file:Main.java
public static NamespaceContext getNamespaceContext(final String prefix, final String uri) { return new NamespaceContext() { @Override//from w w w. java 2 s.c o m public String getNamespaceURI(String prefix) { return uri; } @Override public String getPrefix(String uri) { return prefix; } @Override public Iterator<String> getPrefixes(String uri) { ArrayList<String> prefixes = new ArrayList<String>(); prefixes.add(prefix); return prefixes.iterator(); } }; }
From source file:Capabilities.java
/** Print a list of SET capabilities to stdout, one capability per line * @param obj The Object for which to print the capabilities *///from w w w .java 2 s . com public static void printCapabilities(javax.media.j3d.SceneGraphObject obj) { ArrayList list = new ArrayList(); getCapabilities(obj, list); java.util.Iterator it = list.iterator(); while (it.hasNext()) System.out.println((String) it.next()); }
From source file:com.ning.hfind.primary.ExpressionFactory.java
public static Iterator<Option> sanitizeCommandLine(Option[] options) { ArrayList<Option> optionsList = new ArrayList<Option>(Arrays.asList(options)); Iterator<Option> optionIterator = (Iterator<Option>) optionsList.iterator(); while (optionIterator.hasNext()) { Option option = optionIterator.next(); try {/*from w w w. ja v a 2 s . c om*/ if (PrimaryFactory.primaryFromOption(option) == null) { optionIterator.remove(); } } catch (MalformedPatternException ignored) { } catch (IllegalArgumentException ignored) { } } return optionsList.iterator(); }
From source file:com.alibaba.napoli.client.util.NapoliTestUtil.java
public static <T> void printArray(ArrayList<T> array) { Iterator it = array.iterator(); while (it.hasNext()) { System.out.println(it.next()); }/*from ww w. j a v a2 s . c om*/ }
From source file:info.globalbus.dkim.DKIMUtil.java
protected static String concatArray(ArrayList<String> l, String separator) { StringBuffer buf = new StringBuffer(); Iterator<String> iter = l.iterator(); while (iter.hasNext()) { buf.append(iter.next()).append(separator); }//www. j a v a2 s .co m return buf.substring(0, buf.length() - separator.length()); }
From source file:Main.java
/** * Adds a new node to a file./*from w w w . j a v a 2 s . co m*/ * * @param nodeType {@link String} The type of the element to add. * @param idField {@link String} The name of the field used to identify this * node. * @param nodeID {@link String} The identifier for this node, so its data * can be later retrieved and modified. * @param destFile {@link File} The file where the node must be added. * @param attributes {@link ArrayList} of array of String. The arrays must * be bidimensional (first index must contain attribute name, second one * attribute value). Otherwise, an error will be thrown. However, if * <value>null</value>, it is ignored. */ public static void addNode(String nodeType, String idField, String nodeID, File destFile, ArrayList<String[]> attributes) { if (attributes != null) { for (Iterator<String[]> it = attributes.iterator(); it.hasNext();) { if (it.next().length != 2) { throw new IllegalArgumentException("Invalid attribute combination"); } } } /* * XML DATA CREATION - BEGINNING */ DocumentBuilder docBuilder; Document doc; try { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = docBuilder.parse(destFile); } catch (SAXException | IOException | ParserConfigurationException ex) { return; } Node index = doc.getFirstChild(), newElement = doc.createElement(nodeType); NamedNodeMap elementAttributes = newElement.getAttributes(); Attr attrID = doc.createAttribute(idField); attrID.setValue(nodeID); elementAttributes.setNamedItem(attrID); if (attributes != null) { for (Iterator<String[]> it = attributes.iterator(); it.hasNext();) { String[] x = it.next(); Attr currAttr = doc.createAttribute(x[0]); currAttr.setValue(x[1]); elementAttributes.setNamedItem(currAttr); } } index.appendChild(newElement); /* * XML DATA CREATION - END */ /* * XML DATA DUMP - BEGINNING */ Transformer transformer; try { transformer = TransformerFactory.newInstance().newTransformer(); } catch (TransformerConfigurationException ex) { return; } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(doc); try { transformer.transform(source, result); } catch (TransformerException ex) { return; } String xmlString = result.getWriter().toString(); try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(destFile))) { bufferedWriter.write(xmlString); } catch (IOException ex) { } /* * XML DATA DUMP - END */ }
From source file:com.sleazyweasel.pandora.XmlRpc.java
public static String makeCall(String method, ArrayList<Object> args) { StringBuilder argsStr = new StringBuilder(); Iterator<Object> argsIter = args.iterator(); while (argsIter.hasNext()) { Object item = argsIter.next(); argsStr.append("<param>").append(valueGuess(item)).append("</param>"); }//from w ww . j a va2 s . c o m return "<?xml version=\"1.0\"?><methodCall><methodName>" + method + "</methodName><params>" + argsStr.toString() + "</params></methodCall>"; }
From source file:edu.gsgp.utils.Utils.java
/** * Generates an array with a number of folds defined by the user. Each fold * contains dataset.size() / numFolds instances. * @param numFolds Number of folds/*w w w. java 2s . co m*/ * @param dataset Input datase * @param rnd Random number generator * @return An array of folds */ public static Dataset[] getFoldSampling(int numFolds, Dataset dataset, MersenneTwister rnd) { Dataset[] folds = new Dataset[numFolds]; ArrayList<Instance> dataCopy = dataset.softClone(); int foldIndex = 0; if (rnd == null) { Iterator<Instance> it = dataCopy.iterator(); while (it.hasNext()) { if (folds[foldIndex] == null) folds[foldIndex] = new Dataset(); folds[foldIndex].add(it.next()); it.remove(); if (foldIndex < numFolds - 1) foldIndex++; else foldIndex = 0; } } else { while (!dataCopy.isEmpty()) { if (folds[foldIndex] == null) folds[foldIndex] = new Dataset(); folds[foldIndex].add(dataCopy.remove(rnd.nextInt(dataCopy.size()))); if (foldIndex < numFolds - 1) foldIndex++; else foldIndex = 0; } } return folds; }