List of usage examples for java.util LinkedList LinkedList
public LinkedList(Collection<? extends E> c)
From source file:Main.java
/** * Sorts a collection using a comparator and returns it as a {@link List} * * @param c Collection to be sorted * @param k Comparator to sort by/*from w w w.ja va 2 s . co m*/ * @param reverse Whether to reverse the sort order * @return a {@link List} of the sorted elements * @throws IllegalAccessException when unable to access the comparator class * @throws InstantiationException when unable to instantiate to comparator class */ public static <E> List<E> sortByCompare(Collection<E> c, Class<? extends Comparator<E>> k, boolean reverse) throws IllegalAccessException, InstantiationException { Comparator<E> comp = k.newInstance(); int moves = 0; boolean firstRun = true; LinkedList<E> l = new LinkedList<>(c); while (moves > 0 || firstRun) { firstRun = false; moves = 0; for (int i = 1; i < l.size(); i++) { E a = l.get(i - 1); E b = l.get(i); if (reverse ? comp.compare(a, b) < 0 : comp.compare(a, b) > 0) { l.set(i - 1, b); l.set(i, a); moves++; } } } return l; }
From source file:com.hp.autonomy.hod.client.api.resource.Resources.java
@JsonCreator Resources(@JsonProperty("resources") final List<ResourceDetails> resources) { this.resources = new LinkedList<>(resources); }
From source file:Main.java
/** * <p>/*w w w .j a va2 s .c o m*/ * Checks if the given two {@link Collection}s contains the same elements * in any order. * </p> * <p> * Empty {@link Collection}s and {@code null} parameters are treated as equal. * </p> * @param first The first {@link Collection}. * @param second The second {@link Collection}. * @return {@code true} both {@link Collection}s contains same elements, {@code false} {@link Collection}s are different. */ public static <T> boolean containsSame(Collection<T> first, Collection<T> second) { if (first != null) { if (second != null) { if (first.size() == second.size()) { Collection<T> firstCopy = new LinkedList<T>(first); boolean same = true; Iterator<T> secondIter = second.iterator(); while (same && secondIter.hasNext()) { T secondNext = secondIter.next(); same = firstCopy.remove(secondNext); } return same; } else { return false; } } else { return first.size() == 0; } } else { return second == null || second.size() == 0; } }
From source file:com.ginema.api.reflection.ReflectionUtils.java
public static Stream<Field> getAnnotatedFields(Object a, Class annotation) { List<Field> declaredFields = new LinkedList<>(Arrays.asList(a.getClass().getDeclaredFields())); return declaredFields.stream().filter(p -> p.getAnnotation(annotation) != null); }
From source file:Main.java
public static <E, V extends Comparable<? super V>, K> Map<K, V> sortByValueDesc(Map<K, V> map, int limit) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { return (o2.getValue()).compareTo(o1.getValue()); }//from w w w. j a va2 s .com }); Map<K, V> result = new LinkedHashMap<K, V>(); int counter = 0; for (Map.Entry<K, V> entry : list) { if (limit > 0 && counter >= limit) { break; } result.put(entry.getKey(), entry.getValue()); counter++; } return result; }
From source file:com.playtech.portal.platform.portlet.spring.InternalResourceViewResolver.java
protected String viewNameForLicensee(String viewName) { String[] pathParts = split(viewName, "/"); if (pathParts == null) return null; Deque<String> deque = new LinkedList<>(asList(pathParts)); String view = deque.pollLast(); deque.offer(licenseePackageName);//w w w. j a va2 s . co m deque.offer(view); return join(deque, "/"); }
From source file:com.abuabdul.notedovn.util.NoteDovnUtil.java
public static LinkedList<NotesFolder> wrapInFolder(LinkedList<ScratchNote> notes) { int size = notes.size(); int folderSize = (size % 3) == 0 ? size / 3 : size / 3 + 1; LinkedList<NotesFolder> notesFolders = new LinkedList<>(new ArrayList<NotesFolder>(folderSize)); if (!isEmpty(notes)) { notes = groupByCategoryOrDate(notes); for (int j = 0; j < folderSize; j++) { NotesFolder folder = new NotesFolder(); for (int i = 1; i <= 3; i++) { folder.set(i, when(size - 1, notes)); size--;/*w ww . j a va2s .com*/ } notesFolders.add(folder); } } return notesFolders; }
From source file:Main.java
public void sortByValue() { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { public int compare(Map.Entry<K, V> entry1, Map.Entry<K, V> entry2) { return entry1.getValue().compareTo(entry2.getValue()); }// ww w . j a va 2s. c o m }); clear(); for (Map.Entry<K, V> entry : list) { put(entry.getKey(), entry.getValue()); } }