List of usage examples for java.util LinkedList LinkedList
public LinkedList(Collection<? extends E> c)
From source file:Main.java
/** * Returns a list of the comma-separated input values. * * @param <A> Value type/*from w w w . j a v a 2s. c o m*/ * @param values Comma-separated input values * @return List of values (iteration order equal to insertion order) */ public static <A> List<A> listOf(A... values) { return new LinkedList<A>(Arrays.asList(values)); }
From source file:Main.java
/** * Returns a filtered copy of the collection <code>coll</code>. * * @param coll the collection to filter. * @param p the predicate to filter by.//from w ww. j a va 2 s .c o m * @return a new collection. */ /*public static <T> Collection<T> filter(Collection<T> coll, Predicate<T> p){ Collection<T> c2 = newCollection(coll); for(T obj: coll) if(p.apply(obj)) c2.add(obj); return c2; }*/ private static <T> Collection<T> cloneCollection(Collection<T> coll) { try { Class cl = coll.getClass(); Constructor con = cl.getConstructor(new Class[] { Collection.class }); return (Collection<T>) con.newInstance(new Object[] { coll }); } catch (Exception e) { if (coll instanceof List) return new LinkedList<T>(coll); if (coll instanceof Set) return new HashSet<T>(coll); throw new RuntimeException("Cannot handle this collection"); } }
From source file:Main.java
/** * Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of * InetSocketAddress/*w w w .j av a 2s .c om*/ */ public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) { StringTokenizer tok = new StringTokenizer(hosts, ","); String t; InetSocketAddress addr; Set<InetSocketAddress> retval = new HashSet<InetSocketAddress>(); while (tok.hasMoreTokens()) { t = tok.nextToken().trim(); String host = t.substring(0, t.indexOf('[')); host = host.trim(); int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']'))); for (int i = port; i < port + port_range; i++) { addr = new InetSocketAddress(host, i); retval.add(addr); } } return new LinkedList<InetSocketAddress>(retval); }
From source file:at.bitfire.davdroid.DavUtils.java
public static String lastSegmentOfUrl(@NonNull String url) { // the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy List<String> segments = new LinkedList<>(HttpUrl.parse(url).pathSegments()); Collections.reverse(segments); for (String segment : segments) if (!StringUtils.isEmpty(segment)) return segment; return "/"; }
From source file:deck36.yaml.YamlLoader.java
public static List updateMap(List start, List addendum) { LinkedList result = new LinkedList(start); result.addAll(addendum);/* w ww. j a va 2 s. com*/ return result; }
From source file:Main.java
/** * Returns of linked list of the objects given in the vararg. * * @param contents the objects to return in the list. * @param <T> the class the given objects are instantiations of. * @return a linked list containing the given contents. * @throws AssertionError if any of the contents are not the same type. *///from w w w .j ava2 s. c om public static <T> List<T> listOf(T... contents) { // Check all items in set are of same type... Class first_class = null; for (Object item : contents) { if (first_class == null) { first_class = item.getClass(); } else { assert first_class == item.getClass(); } } return new LinkedList<T>(Arrays.asList(contents)); }
From source file:Main.java
/** * Compares the content of the two list, no matter how they are ordered * @param test the list containing items to check * @param control the list containing the expected values * @return {@code true}//w w w. j a v a2 s .c o m */ public static <T extends Comparable<? super T>> boolean containsInAnyOrder(final List<T> test, final List<T> control) { if (test == null || control == null) { return false; } if (test.size() != control.size()) { return false; } final List<T> orderedControl = new LinkedList<T>(control); Collections.sort(orderedControl); final List<T> orderedTest = new LinkedList<T>(test); Collections.sort(orderedTest); final Iterator<T> testIterator = orderedTest.iterator(); for (Iterator<T> controlIterator = orderedControl.iterator(); controlIterator.hasNext();) { T controlItem = controlIterator.next(); T testItem = testIterator.next(); if (testItem == null || !testItem.equals(controlItem)) { return false; } } return true; }
From source file:Main.java
/** * Creates a new {@link LinkedList} with the provided elements. * * @param <E>//from w w w.j a v a 2s. com * the elements' type * @param elements * the elements to add to the new LinkedList * @return a new LinkedList with the provided elements */ public static <E> LinkedList<E> newLinkedList(E... elements) { return new LinkedList<>(Arrays.asList(elements)); }
From source file:Main.java
/** * Creates a new sorted map, based on the values from the given map and Comparator. * /*w ww.j a v a 2s . c o m*/ * @param map the map which needs to be sorted * @param valueComparator the Comparator * @return a new sorted map */ public static <K, V> Map<K, V> sortMapByValue(Map<K, V> map, Comparator<Entry<K, V>> valueComparator) { if (map == null) { return Collections.emptyMap(); } List<Entry<K, V>> entriesList = new LinkedList<>(map.entrySet()); // Sort based on the map's values Collections.sort(entriesList, valueComparator); Map<K, V> orderedMap = new LinkedHashMap<>(entriesList.size()); for (Entry<K, V> entry : entriesList) { orderedMap.put(entry.getKey(), entry.getValue()); } return orderedMap; }
From source file:Main.java
public static <T> List<T> asList(final Iterable<? extends T> iterable) { return (iterable instanceof Collection) ? new LinkedList<T>((Collection<? extends T>) iterable) : new LinkedList<T>() { private static final long serialVersionUID = 3109256773218160485L; {// www .java 2 s. c o m if (iterable != null) { for (final T t : iterable) { add(t); } } } }; }