List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
public static <T> List<T> toList(Iterable<T> iterable) { if (null == iterable) return Collections.emptyList(); List<T> retList = new LinkedList<>(); for (T item : iterable) { retList.add(item);/*from w w w.ja v a 2s .c o m*/ } return retList; }
From source file:Main.java
public static List<Element> getChildsWithName(Element root, String name) { NodeList childNodes = root.getElementsByTagName(name); List<Element> elementList = new LinkedList<Element>(); for (int i = 0; i < childNodes.getLength(); ++i) { elementList.add((Element) childNodes.item(i)); }//w ww . j ava 2s . co m return elementList; }
From source file:Main.java
public static List<File> listFilesByName(File f) { Log.d("listFileByName f", "" + f); final List<File> fList = new LinkedList<>(); final Stack<File> stk = new Stack<>(); if (f.isDirectory()) { stk.push(f);/*from w w w. j a v a 2 s .co m*/ } else { fList.add(f); } File fi = null; File[] fs; while (stk.size() > 0) { fi = stk.pop(); fs = fi.listFiles(); for (File f2 : fs) { if (f2.isDirectory()) { stk.push(f2); } else { fList.add(f2); } } } return fList; }
From source file:Main.java
protected static List<Node> createRealNodeList(NodeList nodeList) { List<Node> realNodeList = new LinkedList<Node>(); if (null != nodeList && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); ++i) { Node nextNode = nodeList.item(i); realNodeList.add(nextNode);/*from w w w . j a va 2 s. com*/ } } return realNodeList; }
From source file:Main.java
public static <T> List<T> arrayToList(T[] objs) { if (isEmpty(objs)) { return null; }//from www .j a va2s .com List<T> list = new LinkedList<T>(); for (T obj : objs) { list.add(obj); } return list; }
From source file:Main.java
public static List<Element> getElementCollectionFromDocument(Document document, String tagName) { List<Element> res = new LinkedList<Element>(); NodeList entries = document.getElementsByTagName(tagName); for (int i = 0; i < entries.getLength(); i++) { Node entry = entries.item(i); if (entry.getNodeType() == Node.ELEMENT_NODE) { res.add((Element) entry); }// w w w . ja v a 2s . c o m } return res; }
From source file:Main.java
public static List childNodeList(Node node, String childNodeName) { if (node == null) return null; List children = new LinkedList(); Node childNode = node.getFirstChild(); if (childNode != null) { do {/*from ww w . ja va 2s. c o m*/ if (childNode.getNodeType() == Node.ELEMENT_NODE && (childNodeName == null || childNodeName.equals(childNode.getNodeName()))) { children.add(childNode); } } while ((childNode = childNode.getNextSibling()) != null); } return children; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> List<T> toGenericList(Iterable<?> it) { if (it instanceof List) { return (List<T>) it; }//from w w w . j av a 2 s . com final List<T> result = new LinkedList<T>(); for (final Object t : it) { result.add((T) t); } return result; }
From source file:Main.java
public static LinkedList<Integer> retrieveIntegerFromCursor(Cursor cursor, String columnName) { if (null == cursor || 0 == cursor.getCount()) { return new LinkedList<Integer>(); }/* w ww . j a v a 2s .co m*/ LinkedList<Integer> ids = new LinkedList<Integer>(); try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndexOrThrow(columnName)); ids.add(new Integer(id)); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return ids; }
From source file:Main.java
public static String[] intersect(String[] arr1, String[] arr2) { Map<String, Boolean> map = new HashMap<>(); LinkedList<String> list = new LinkedList<>(); for (String str : arr1) { if (!map.containsKey(str)) { map.put(str, Boolean.FALSE); }/* ww w .j a v a2s . c o m*/ } for (String str : arr2) { if (map.containsKey(str)) { map.put(str, Boolean.TRUE); } } for (Map.Entry<String, Boolean> e : map.entrySet()) { if (e.getValue().equals(Boolean.TRUE)) { list.add(e.getKey()); } } String[] result = {}; return list.toArray(result); }