List of usage examples for java.util LinkedHashSet LinkedHashSet
public LinkedHashSet()
From source file:Main.java
public static <T, V extends T> LinkedHashSet<T> createLinkedHashSet(V... args) { if (args == null || args.length == 0) { return new LinkedHashSet<T>(); }//from w w w. j av a 2s . co m LinkedHashSet<T> set = new LinkedHashSet<T>(args.length); for (V v : args) { set.add(v); } return set; }
From source file:Main.java
/** * @param elements//from w ww. j av a 2 s. c om * @param maxNumber * @return the maxNumber of elements in ids and rest are skipped */ public static <T> Set<T> getElementsOfMaxSize(Set<T> elements, int maxNumber) { // The returned set should maintain the same order as the input elements Set<T> maxIds = new LinkedHashSet<T>(); if (maxNumber <= 0) { return maxIds; } for (T id : elements) { maxIds.add(id); maxNumber--; if (maxNumber <= 0) { break; } } elements.removeAll(maxIds); return maxIds; }
From source file:Main.java
/** * Removes the duplicates./* ww w . j a v a 2 s .c om*/ * * @param <T> * the generic type * @param items * the items * @return the list */ public static <T> List<T> removeDuplicates(List<T> items) { Set<T> set = new LinkedHashSet<T>(); set.addAll(items); return new ArrayList<T>(set); }
From source file:Main.java
public static <T, V extends T> LinkedHashSet<T> createLinkedHashSet(V... args) { if (args == null || args.length == 0) { return new LinkedHashSet<T>(); } else {//from ww w .j a va2 s .c o m LinkedHashSet<T> set = new LinkedHashSet<T>(args.length); for (V v : args) { set.add(v); } return set; } }
From source file:Main.java
private static Set<String> getQueryParameterNames(Uri uri) { if (uri.isOpaque()) { throw new UnsupportedOperationException("This isn't a hierarchical URI."); }//from ww w. ja va 2 s . com String query = uri.getEncodedQuery(); if (query == null) { return Collections.emptySet(); } Set<String> names = new LinkedHashSet<String>(); int start = 0; do { int next = query.indexOf('&', start); int end = (next == -1) ? query.length() : next; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } String name = query.substring(start, separator); names.add(Uri.decode(name)); // Move start to end of name. start = end + 1; } while (start < query.length()); return Collections.unmodifiableSet(names); }
From source file:Main.java
/** * it returns an ordered Set implementation * /*from w w w. ja v a2 s . c o m*/ * @return */ public static <T> Set<T> newOrderedSet() { return new LinkedHashSet<>(); }
From source file:Main.java
public static Set<String> getQueryParameterNames(Uri uri) { if (uri.isOpaque()) { throw new UnsupportedOperationException("This isn't a hierarchical URI."); }/*from w w w. java2 s . com*/ String query = uri.getEncodedQuery(); if (query == null) { return Collections.emptySet(); } Set<String> names = new LinkedHashSet<String>(); int start = 0; do { int next = query.indexOf('&', start); int end = next == -1 ? query.length() : next; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } String name = query.substring(start, separator); names.add(Uri.decode(name)); // Move start to end of name. start = end + 1; } while (start < query.length()); return Collections.unmodifiableSet(names); }
From source file:Main.java
public static <K, V> Set<V> lookup(Map<K, V> map, Collection<K> keys) { Set<V> result = new LinkedHashSet<V>(); for (K key : keys) { V e = map.get(key);/*from w w w .j a v a 2 s . c o m*/ if (e != null) { result.add(e); } } return result; }
From source file:Main.java
public static <T> Set<T> createDefaultSet() { return new LinkedHashSet<T>(); }
From source file:Main.java
/** * Adds the value to map. If the key does not exists new value set is created and the value is * added to it/*from w ww. j a v a2 s . com*/ * * @param <K> * the key type * @param <V> * the value type * @param map * the map * @param key * the key * @param newValue * the new value */ public static <K, V> void addValueToSetMap(Map<K, Set<V>> map, K key, V newValue) { Set<V> list = map.get(key); if (list == null) { list = new LinkedHashSet<V>(); map.put(key, list); } list.add(newValue); }