List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
public static Collection<Node> search_nodes_by_attribute(Node root, String attr_name, String attr_value) { Collection<Node> result = new LinkedList<Node>(); if (root instanceof Element) { if (((Element) root).hasAttribute(attr_name) && ((Element) root).getAttribute(attr_name).equals(attr_value)) result.add(root);//from www.java 2s . c o m } NodeList list = root.getChildNodes(); for (int i = 0; i < list.getLength(); ++i) { Node child = list.item(i); Collection<Node> ret = search_nodes_by_attribute(child, attr_name, attr_value); result.addAll(ret); } return result; }
From source file:Main.java
public static String[] getChildrenText(Element parentElement, String childrenName) { NodeList nl = parentElement.getChildNodes(); int max = nl.getLength(); LinkedList<String> list = new LinkedList<String>(); for (int i = 0; i < max; i++) { Node n = nl.item(i);// w w w. jav a 2s.c o m if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(childrenName)) { list.add(getText((Element) n)); } } return list.toArray(new String[list.size()]); }
From source file:Main.java
public static List<String> parseStringList(String l, String separator) { List<String> tmp = new LinkedList<String>(); StringTokenizer tok = new StringTokenizer(l, separator); String t;/* ww w . jav a 2 s . com*/ while (tok.hasMoreTokens()) { t = tok.nextToken(); tmp.add(t.trim()); } return tmp; }
From source file:Main.java
public static <V> List<Future<V>> submitTasks(ExecutorCompletionService<V> ecs, Iterable<Callable<V>> tasks) { List<Future<V>> futures = new LinkedList<>(); if (tasks != null) { for (Callable<V> callable : tasks) { futures.add(ecs.submit(callable)); }//from w w w.j a v a 2s. c o m } return futures; }
From source file:Main.java
public static LinkedList<Pair<Integer, String>> retrieveIntegerStringPairFromCursor(Cursor cursor, String integerColumnName, String stringColumnName) { LinkedList<Pair<Integer, String>> result = new LinkedList<Pair<Integer, String>>(); if (null == cursor || 0 == cursor.getCount()) { return result; }/*from www. j a va 2 s . co m*/ try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { Integer integerVal = cursor.getInt(cursor.getColumnIndex(integerColumnName)); String stringVal = cursor.getString(cursor.getColumnIndexOrThrow(stringColumnName)); result.add(new Pair(integerVal, stringVal)); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return result; }
From source file:Main.java
private static List<String> getStreamCallableResult(Future<List<String>> future) throws Exception { List<String> streamResult = readCallableResult(future); return streamResult == null ? new LinkedList<String>() : streamResult; }
From source file:Main.java
public static LinkedList<String> uc_unserialize(String input) { LinkedList result = new LinkedList(); DOMParser parser = new DOMParser(); try {//w w w. j a v a 2 s . c o m parser.parse(new InputSource(new StringReader(input))); Document doc = parser.getDocument(); NodeList nl = doc.getChildNodes().item(0).getChildNodes(); int length = nl.getLength(); for (int i = 0; i < length; i++) if (nl.item(i).getNodeType() == 1) result.add(nl.item(i).getTextContent()); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static LinkedList<String> uc_unserialize(String input) { LinkedList result = new LinkedList(); DOMParser parser = new DOMParser(); try {/* w w w . ja v a 2s. co m*/ parser.parse(new InputSource(new StringReader(input))); Document doc = parser.getDocument(); NodeList nl = doc.getChildNodes().item(0).getChildNodes(); int length = nl.getLength(); for (int i = 0; i < length; ++i) if (nl.item(i).getNodeType() == 1) result.add(nl.item(i).getTextContent()); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * Returns a list of the direct child {@link Element}s of the given parent. * //w w w .j av a 2s . c o m * @param parent The parent element. */ public static List<Element> getChildElements(Element parent) { List<Element> childElements = new LinkedList<Element>(); NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode instanceof Element) childElements.add((Element) childNode); } return childElements; }
From source file:Main.java
/**a Convenience method that turns a NodeList into a LinkedList of Nodes * which allows for iteration//from ww w .j a va2s.c o m * @param elm * @param str * @return */ public static List<Node> getNodeListAsList(NodeList nList) {//Element elm, String str){ List<Node> aList = new LinkedList<Node>(); for (int i = 0; i < nList.getLength(); i++) aList.add(nList.item(i)); return aList; }