List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
public static <T> LinkedList<T> toLinkedList(final Iterator<T> iter) { return addTo(iter, new LinkedList<T>()); }
From source file:Main.java
public static Collection extractField(Collection in, String fieldName, Class type) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Iterator<Object> it = in.iterator(); boolean isBoolean = (type == Boolean.class || type == boolean.class); String methodName = (isBoolean) ? "is" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1) //$NON-NLS-1$ : "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); //$NON-NLS-1$ LinkedList<Object> out = new LinkedList<Object>(); while (it.hasNext()) { Object obj = it.next();/*from w w w .j av a 2 s .com*/ Method m = obj.getClass().getMethod(methodName, new Class[] {}); Object value2 = m.invoke(obj, null); out.add(value2); } return out; }
From source file:Main.java
/** Convert coordination of face point to screen rect that will be draw on canvas<br> */ public static List<Point> convertFacePoint(boolean frontCamera, float displayOrientation, float viewWidth, float viewHeight, Point... points) { Matrix matrix = createConvertMatrix(frontCamera, displayOrientation, viewWidth, viewHeight); float[] pts = new float[points.length * 2]; for (int i = 0; i < points.length; ++i) { pts[i * 2] = points[i].x;/*from w w w .j a v a2 s. c o m*/ pts[i * 2 + 1] = points[i].y; } matrix.mapPoints(pts); List<Point> result = new LinkedList<>(); for (int j = 0; j < pts.length; j += 2) { result.add(new Point((int) pts[j], (int) pts[j + 1])); } return result; }
From source file:Main.java
public static <T> LinkedList<T> createLinkedList() { return new LinkedList<T>(); }
From source file:Main.java
/** * Returns the ordered keys of the given map * /*from www . j av a 2 s . co m*/ * @param map * the map * @return the ordered keys */ public final static List<String> getOrderedKeys(final Map<String, Object> map) { List<String> keys = new LinkedList<String>(); if (!map.isEmpty()) { keys.addAll(map.keySet()); Collections.sort(keys, new Comparator<String>() { /** * {@inheritDoc} */ public int compare(String o1, String o2) { if (o1 == o2) { return 0; } int n1 = -1; int n2 = -1; try { n1 = Integer.parseInt(o1.substring(1)); } catch (NumberFormatException e) { // IGNORE } try { n2 = Integer.parseInt(o2.substring(1)); } catch (NumberFormatException e) { // IGNORE } /* * n1 is a number */ if (n1 != -1) { /* * n2 is a number */ if (n2 != -1) { return n1 - n2; } /* * n2 is a string literal */ return -1; } /* * n1 is a literal and n2 is a number */ if (n2 != -1) { return -1; } /* * both are literals */ return o1.compareTo(o2); } }); } return keys; }
From source file:Main.java
/** * Transformation operation for a {@link Collection} to a {@link List}. * /*from w w w. j a va 2 s . co m*/ * @param <E> * the type of the given and returned values * @param collection * the collection to transform * @return the new {@link List}, containing all entries of the given * collection */ public static <E extends Object> List<E> asList(Collection<E> collection) { List<E> list = new LinkedList<E>(); list.addAll(collection); return list; }
From source file:Main.java
public static List<String> getDexEntries() { try {/*from ww w .java 2 s.c o m*/ Object app = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null); Object codePath = Class.forName("android.app.Application").getMethod("getPackageCodePath").invoke(app); Class<?> dexFileClass = Class.forName("dalvik.system.DexFile"); Object dexFile = dexFileClass.getConstructor(String.class).newInstance(codePath); Enumeration<String> entries = (Enumeration<String>) dexFileClass.getMethod("entries").invoke(dexFile); List<String> dexEntries = new LinkedList<>(); while (entries.hasMoreElements()) { String entry = entries.nextElement(); entry = entry.replace('.', '/') + ".class"; dexEntries.add(entry); } dexFileClass.getMethod("close").invoke(dexFile); return dexEntries; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Constructs a new synchronized {@code List} based on a {@link LinkedList}. * //from w ww .j av a2 s .co m * @return a synchronized List */ public static <E> List<E> synchronizedList() { return Collections.synchronizedList(new LinkedList<E>()); }
From source file:Main.java
public static List<String> getDexEntries() { try {/*from w w w. j a v a 2s. co m*/ Object app = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null); Object codePath = Class.forName("android.app.Application").getMethod("getPackageCodePath").invoke(app); Class<?> dexFileClass = Class.forName("dalvik.system.DexFile"); Object dexFile = dexFileClass.getConstructor(String.class).newInstance(codePath); Enumeration<String> entries = (Enumeration<String>) dexFileClass.getMethod("entries").invoke(dexFile); List<String> dexEntries = new LinkedList<String>(); while (entries.hasMoreElements()) { String entry = entries.nextElement(); entry = entry.replace('.', '/') + ".class"; dexEntries.add(entry); } dexFileClass.getMethod("close").invoke(dexFile); return dexEntries; } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (SecurityException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Returns a new list containing the second list appended to the first list. *///w w w .j a v a 2 s . c o m public static <T> List<T> mergeLists(List<T> list1, List<T> list2) { List<T> merged = new LinkedList<T>(); if (list1 != null) { merged.addAll(list1); } if (list2 != null) { merged.addAll(list2); } return merged; }