List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
public static Map<String, List<String>> createDictionary(Context context) { try {//from ww w . ja v a2 s .co m AssetManager am = context.getAssets(); InputStream is = am.open(DICTIONARY_FILENAME); Scanner reader = new Scanner(is); Map<String, List<String>> map = new HashMap<String, List<String>>(); while (reader.hasNextLine()) { String word = reader.nextLine(); char[] keyArr = word.toCharArray(); Arrays.sort(keyArr); String key = String.copyValueOf(keyArr); List<String> wordList = map.get(key); if (wordList == null) { wordList = new LinkedList<String>(); } wordList.add(word); map.put(key, wordList); } reader.close(); return map; } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } return null; }
From source file:Main.java
public static List<String> getAllLeaveValues(Element element) throws XPathExpressionException { if (element == null) { return null; }/* w w w .j a v a 2s . co m*/ List<String> ret = new LinkedList<String>(); if (isLeaf(element)) { ret.add(element.getTextContent()); } else { NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { Element childElement = (Element) n; for (String childText : getAllLeaveValues(childElement)) { ret.add(childText); } } } } return ret; }
From source file:ClassUtil.java
/** * Retrieving fields list of specified class * If recursively is true, retrieving fields from all class hierarchy * * @param clazz where fields are searching * @param recursively param//from w w w .ja va 2 s . c o m * @return list of fields */ public static Field[] getDeclaredFields(Class clazz, boolean recursively) { List<Field> fields = new LinkedList<Field>(); Field[] declaredFields = clazz.getDeclaredFields(); Collections.addAll(fields, declaredFields); Class superClass = clazz.getSuperclass(); if (superClass != null && recursively) { Field[] declaredFieldsOfSuper = getDeclaredFields(superClass, recursively); if (declaredFieldsOfSuper.length > 0) Collections.addAll(fields, declaredFieldsOfSuper); } return fields.toArray(new Field[fields.size()]); }
From source file:Main.java
/** * //www. j a v a 2 s . co m * @param zipFile * zip file * @param folderName * folder to load * @return list of entry in the folder * @throws ZipException * @throws IOException */ public static List<ZipEntry> loadFiles(File zipFile, String folderName) throws ZipException, IOException { Log.d("loadFiles", folderName); long start = System.currentTimeMillis(); FileInputStream fis = new FileInputStream(zipFile); BufferedInputStream bis = new BufferedInputStream(fis); ZipInputStream zis = new ZipInputStream(bis); ZipEntry zipEntry = null; List<ZipEntry> list = new LinkedList<ZipEntry>(); String folderLowerCase = folderName.toLowerCase(); int counter = 0; while ((zipEntry = zis.getNextEntry()) != null) { counter++; String zipEntryName = zipEntry.getName(); Log.d("loadFiles.zipEntry.getName()", zipEntryName); if (zipEntryName.toLowerCase().startsWith(folderLowerCase) && !zipEntry.isDirectory()) { list.add(zipEntry); } } Log.d("Loaded 1", counter + " files, took: " + (System.currentTimeMillis() - start) + " milliseconds."); zis.close(); bis.close(); fis.close(); return list; }
From source file:Main.java
public static void printHexDump(String prefix, @NonNull byte[] data) { List<String> strs = new LinkedList<>(); Log.e("HexDump" + prefix, "========"); String bytes = ""; int i;/* ww w . jav a 2 s. c o m*/ for (i = 0; i < data.length; i++) { bytes += String.format("%02x ", data[i]); if (i > 0 && (i + 1) % 32 == 0) { strs.add(bytes); bytes = ""; } } strs.add(bytes); for (int j = 0; j < strs.size(); j++) { Log.e("HexDump" + prefix + ":" + j, strs.get(j)); } }
From source file:Main.java
public static <T, V extends T> LinkedList<T> createLinkedList(V... args) { LinkedList<T> list = new LinkedList<T>(); if (args != null) { for (V v : args) { list.add(v);// w w w .jav a 2 s .c o m } } return list; }
From source file:Main.java
private static void removeEmptyChildElements(Element parentElement) { List<Element> toRemove = new LinkedList<Element>(); NodeList children = parentElement.getChildNodes(); int childrenCount = children.getLength(); for (int i = 0; i < childrenCount; ++i) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; removeEmptyChildElements(childElement); if (elementIsRedundant(childElement)) { toRemove.add(childElement); }//from w ww.ja v a 2s . com } } for (Element childElement : toRemove) { parentElement.removeChild(childElement); } parentElement.normalize(); }
From source file:Main.java
/** * Get all the direct children elements of an element that have a specific * tag name./*from w w w. ja va 2 s . c o m*/ * * @param parent * The parent element. * @param name * The tag name to match. * * @return A list of Element's. */ public static List<Element> getElements(final Element parent, final String name) { final LinkedList<Element> list = new LinkedList<Element>(); Node node = parent.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) node; if (element.getTagName().equals(name)) { list.add(element); } } node = node.getNextSibling(); } return list; }
From source file:Main.java
/** Credit Victor from StackOverflow * Combines several collections of elements and create permutations of all of them, taking one element from each * collection, and keeping the same order in resultant lists as the one in original list of collections. * * <ul>Example// w ww.j a v a 2s.c om * <li>Input = { {a,b,c} , {1,2,3,4} }</li> * <li>Output = { {a,1} , {a,2} , {a,3} , {a,4} , {b,1} , {b,2} , {b,3} , {b,4} , {c,1} , {c,2} , {c,3} , {c,4} }</li> * </ul> * * @param collections Original list of collections which elements have to be combined. * @return Resultant collection of lists with all permutations of original list. */ public static <T> Collection<List<T>> permutations(List<Collection<T>> collections) { if (collections == null || collections.isEmpty()) { return Collections.emptyList(); } else { Collection<List<T>> res = Lists.newLinkedList(); permutationsImpl(collections, res, 0, new LinkedList<T>()); return res; } }
From source file:Main.java
/** * Returns a list of the values of the selected elements from an input map. * It is not backed in the input map, thus changes in this list are not * reflected in the input map./* ww w.ja v a 2 s .c o m*/ * * @param <A> Key type * @param <B> Value type * @param map Input map * @param keys Keys of the elements to be selected * @return List of the values associated to the input indexes (in iteration order) */ public static <A, B> List<B> select(Map<A, B> map, Collection<A> keys) { List<B> out = new LinkedList<B>(); for (A key : keys) if (map.containsKey(key)) out.add(map.get(key)); return out; }