List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
public static LinkedList<Byte> toList(byte[] array) { LinkedList<Byte> resList = new LinkedList<Byte>(); for (int i = 0; i < array.length; i++) { resList.add(array[i]);/*w w w.j a v a2 s. co m*/ } return resList; }
From source file:Main.java
public static <T> List<T> toList(Iterable<T> i) { List<T> list = new LinkedList<T>(); for (T element : i) list.add(element);//from w w w .j a va2 s . c o m return list; }
From source file:Main.java
public static String toString(Iterable<Object> pathItrb) { LinkedList<Object> list = new LinkedList<Object>(); Iterator itr = pathItrb.iterator(); while (itr.hasNext()) { list.addFirst(itr.next());//from w w w . ja va2 s . c om } // StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (Object obj : list) { if (isFirst) { isFirst = false; } else { sb.append("/"); // NOI18N } sb.append(obj.toString()); } // return sb.toString(); }
From source file:Main.java
public static <T> List<T> filterByType(Iterable<?> collection, Class<T> expectedType) { List<T> filtered = new LinkedList<T>(); if (collection != null) { for (Object item : collection) { if (item != null && expectedType.isInstance(item)) { filtered.add(expectedType.cast(item)); }//w ww . j av a2 s . c o m } } return filtered; }
From source file:Main.java
public static List<Attr> getAttributes(Element element) { List<Attr> attributes = new LinkedList<Attr>(); NamedNodeMap namedNodeMap = element.getAttributes(); for (int i = 0; i < namedNodeMap.getLength(); i++) { Node node = namedNodeMap.item(i); if (node.getNodeType() == Node.ATTRIBUTE_NODE) { Attr a = (Attr) node; attributes.add(a);//from w w w .j a va 2s . co m } } return attributes; }
From source file:Main.java
public static List createList(Object item) { List list = new LinkedList(); list.add(item); return list; }
From source file:Main.java
public static List<Element> getElementsByTagName(Element element, String name) { List<Element> elements = new LinkedList<Element>(); NodeList nodeList = element.getElementsByTagName(name); for (int i = 0; i < nodeList.getLength(); i++) { elements.add((Element) nodeList.item(i)); }//w ww. j a va2s .co m return elements; }
From source file:Main.java
public static <T> void rotate(Collection<T> collection, int rotateStep) { List<T> list = new LinkedList<T>(); list.addAll(collection);// w ww . j a v a 2 s . c o m collection.clear(); if (rotateStep > 0) { if (rotateStep > list.size()) rotateStep %= list.size(); collection.addAll(list.subList(list.size() - rotateStep, list.size())); collection.addAll(list.subList(0, list.size() - rotateStep)); } else { if (Math.abs(rotateStep) > list.size()) rotateStep %= list.size(); rotateStep = Math.abs(rotateStep); collection.addAll(list.subList(rotateStep, list.size())); collection.addAll(list.subList(0, rotateStep)); } }
From source file:Main.java
public static int insertX(int numb, int random) { long result = 0; LinkedList<Integer> stack = new LinkedList<Integer>(); while (numb > 0) { stack.push(numb % 10);// w w w.j av a 2 s . c om numb = numb / 10; } while (!stack.isEmpty()) { result = (int) combinedTwoNumber(result, stack.pop()); result = (int) combinedTwoNumber(result, random); } return (int) (result /= 10); }
From source file:Main.java
public static <T> List<T> union(List<List<T>> collections) { if (collections.size() <= 0) { return new LinkedList<>(); } else if (collections.size() == 1) { return collections.get(0); } else {// w ww . j a va 2 s . c o m List<T> result = new LinkedList<>(); for (List<T> list : collections) { result.addAll(list); } return result; } }