List of usage examples for java.util Set addAll
boolean addAll(Collection<? extends E> c);
From source file:Main.java
/** * Returns all the unique fields of the classes in the given list. * @author Tristan Bepler// ww w . j a v a2s .c om */ private static Field[] getAllFields(List<Class<?>> classes) { Set<Field> fields = new HashSet<Field>(); for (Class<?> clazz : classes) { fields.addAll(Arrays.asList(clazz.getDeclaredFields())); } return fields.toArray(new Field[fields.size()]); }
From source file:Main.java
public final static <T> Set<T> unicon(Set<T> set1, Set<T> set2) { Set<T> set = new HashSet<>(set1.size() + set2.size()); set = set1;/*from w ww . j a v a 2 s . com*/ set.addAll(set2); return set; }
From source file:Main.java
/** * Make INTERSECTION operation between 2 {@link Collection} * * @param a//w ww .j a v a 2s .co m * @param b * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection intersection(final Collection a, final Collection b) { final ArrayList list = new ArrayList(); final Map mapa = getCardinalityMap(a); final Map mapb = getCardinalityMap(b); final Set elts = new LinkedHashSet(a); elts.addAll(b); final Iterator it = elts.iterator(); while (it.hasNext()) { final Object obj = it.next(); 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
/** * Make UNION operation between 2 {@link Collection} * * @param a/* ww w . j av a 2s. c o m*/ * @param b * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection union(final Collection a, final Collection b) { final ArrayList list = new ArrayList(); final Map mapa = getCardinalityMap(a); final Map mapb = getCardinalityMap(b); final Set elts = new LinkedHashSet(a); elts.addAll(b); final Iterator it = elts.iterator(); while (it.hasNext()) { final Object obj = it.next(); for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:Main.java
public static <E> Set<E> treeSet(E... add) { Set<E> result = new TreeSet<>(); if (add != null) { result.addAll(Arrays.asList(add)); }/*from w w w. ja v a 2 s .co m*/ return result; }
From source file:Main.java
/** * Returns a {@link Collection} containing the intersection * of the given {@link Collection}s./*from w w w . j av a2 s. com*/ * <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, must not be null * @param b the second collection, must not be null * @return the intersection of the two collections */ public static Collection intersection(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new HashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next(); 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
public static <T> Set<T> union(Set<T> set1, Set<T> set2) { if (isEmpty(set1)) { return set2; }//from w w w . j a v a2 s .co m if (isEmpty(set2)) { return set1; } Set<T> result = createHashSet(set1); result.addAll(set2); return result; }
From source file:com.spotify.echoprintserver.nativelib.Util.java
public static List<Integer> sortedDistinct(List<Integer> seq) { Set<Integer> codeSet = new TreeSet<Integer>(); codeSet.addAll(seq); List<Integer> uniqueSortedCodeSet = new ArrayList<Integer>(); uniqueSortedCodeSet.addAll(codeSet); Collections.sort(uniqueSortedCodeSet); return uniqueSortedCodeSet; }
From source file:de.mpg.imeji.logic.search.util.CollectionUtils.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection union(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new LinkedHashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next();//w ww .j a va2 s .c o m for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:de.mpg.imeji.logic.search.util.CollectionUtils.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection intersection(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new LinkedHashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next();//from w w w . j a va 2s. c o m for (int i = 0, m = Math.min(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }