List of usage examples for java.util Set addAll
boolean addAll(Collection<? extends E> c);
From source file:com.ignorelist.kassandra.steam.scraper.LibraryScanner.java
public static Set<Long> findGames(Iterable<Path> paths) throws IOException { Set<Long> gameIds = new HashSet<>(); for (Path p : paths) { gameIds.addAll(findGames(p)); }// w ww . j a v a2 s .com return gameIds; }
From source file:Main.java
/** * Returns a {@link Collection} containing the intersection * of the given {@link Collection}s./*from www . j a v a2 s. c o m*/ * <p> * The cardinality of each element in the returned {@link Collection} * will be equal to the minimum of the cardinality of that element * in the two given {@link Collection}s. * * @param a The first collection * @param b The second collection * @see Collection#retainAll * @return The intersection of a and b, never null */ public static <E> Collection<E> intersection(final Collection<E> a, final Collection<E> b) { ArrayList<E> list = new ArrayList<E>(); Map<E, Integer> mapa = getCardinalityMap(a); Map<E, Integer> mapb = getCardinalityMap(b); Set<E> elts = new HashSet<E>(a); elts.addAll(b); for (E obj : elts) { for (int i = 0, m = Math.min(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:Main.java
/** * Thread safe method to initialize sets * @param initSet/*from www . j av a2 s. co m*/ * @return an initialized set of the desired object type */ public static synchronized <T> Set<T> initializeSets(Set<T> initSet) { if (initSet == null) { return new HashSet<T>(); } else { initSet.addAll(initSet); return initSet; } }
From source file:com.memetix.gun4j.expand.UrlExpander.java
public static Map<String, String> expand(final List<String> shortUrls) throws Exception { Set<String> urlSet = new HashSet<String>(); urlSet.addAll(shortUrls); return expand(urlSet); }
From source file:Main.java
/** * Returns the unique union of the given lists *//*from w w w .j a v a2s . c o m*/ public static <T> Set<T> setUnion(Collection<T>... lists) { Set<T> union = new HashSet<T>(lists[0].size() * 2); for (int x = 0; x < lists.length; x++) { union.addAll(lists[x]); } return union; }
From source file:Main.java
/** * Bestimmt die Vereinigung zweier Mengen. * //from ww w . j a v a 2 s . com * @param <T> * der Typ der Mengen. * @param set1 * die erste Menge. * @param set2 * die zweite Menge. * @return die Mengenvereinigung. */ public static <T> Set<T> union(final Set<T> set1, final Set<T> set2) { final Set<T> result = new HashSet<T>(); result.addAll(set1); result.addAll(set2); return result; }
From source file:Main.java
/** * Converts the given array of elements to a set. * * @param elements The elements/*from w w w.j a v a 2s . c o m*/ * @return The elements as a set, empty if elements was null */ public static <T> Set<T> asSet(T... elements) { Set<T> result = new HashSet<T>(); if (elements == null) { return result; } result.addAll(asList(elements)); return result; }
From source file:Main.java
/** * Return a new Set with elements that are in the first and second passed collection. * If one set is null, an empty Set will be returned. * @param <T> Type of set/* ww w. j a v a 2 s . c om*/ * @param first First set * @param second Second set * * @return a new set (depending on input type) with elements in first and second */ static <T> Set<T> intersection(Set<T> first, Set<T> second) { Set<T> result = new HashSet<T>(); if ((first != null) && (second != null)) { result.addAll(first); // result.retainAll(second); Iterator<T> iter = result.iterator(); boolean found; while (iter.hasNext()) { T item = iter.next(); found = false; for (T s : second) { if (s.equals(item)) found = true; } if (!found) iter.remove(); } } return result; }
From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java
private static Set<String> getLanguages(String optValue) { Set<String> languages = new HashSet<>(); if (StringUtils.isNotEmpty(optValue)) { languages.addAll(Arrays.asList(optValue.split(","))); }//w w w . ja v a2s . c om return languages; }
From source file:Main.java
/** * This method returns a new HashSet which is the intersection of the two Set parameters, based on {@link Object#equals(Object) equality} * of their elements./*from w w w . jav a 2s .c o m*/ * Any references in the resultant set will be to elements within set1. * * @return a new HashSet whose values represent the intersection of the two Sets. */ public static <T> Set<T> intersect(Set<? extends T> set1, Set<? extends T> set2) { if (set1 == null || set1.isEmpty() || set2 == null || set2.isEmpty()) { return Collections.emptySet(); } Set<T> result = new HashSet<T>(); result.addAll(set1); result.retainAll(set2); return result; }