List of usage examples for java.util Set addAll
boolean addAll(Collection<? extends E> c);
From source file:com.mnt.base.stream.server.ConnectionManager.java
public static Set<String> getConnectionIds() { Set<String> connIds = new HashSet<String>(); connIds.addAll(connectionMap.keySet()); return connIds; }
From source file:Main.java
/** * Returns a cloned Map of String to Set of String. * * @param map Map to be cloned./*from w w w . j a v a 2s .c o m*/ * @return cloned map. */ public static Map<String, Set<String>> cloneMap(Map<String, Set<String>> map) { Map<String, Set<String>> clone = new HashMap<String, Set<String>>(); for (String key : map.keySet()) { Set<String> set = new HashSet<String>(); Set<String> orig = (Set<String>) map.get(key); set.addAll(orig); clone.put(key, set); } return clone; }
From source file:Main.java
/** * As {@link #getAllFields(Class)} but acts on a list of {@link Class}s and * uses only {@link Class#getDeclaredFields()}. * * @param classes The list of classes to reflect on * @return The complete list of fields//from w ww .j av a 2 s . 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
/** * Adds all elements of the <code>src</code> collections to <code>dest</code>, * returning <code>dest</code>. This is typically used when you need to combine * collections temporarily for a method argument. * * @since 1.0.7//from w w w . j a v a2 s.c om */ public static <T> Set<T> combine(Set<T> dest, Collection<T>... src) { for (Collection<T> cc : src) { dest.addAll(cc); } return dest; }
From source file:net.landora.video.filestate.DirectoryUUIDChecker.java
public static void setUUID(File directory, String uuid) { try {//w w w. jav a 2s. co m File uuidFile = new File(directory, UUID_FILE); Set<String> uuids = new LinkedHashSet<String>(); if (uuidFile.exists()) { uuids.addAll(FileUtils.readLines(uuidFile)); } uuids.add(uuid); FileUtils.writeLines(uuidFile, uuids); } catch (Exception e) { log.error("Error adding directory uuid: " + directory, e); } }
From source file:Main.java
/** * @param iterable iterates thru the collections to be merged into one. * @return a Set containing all the elements that are contained in at least one of the given collections. * Note that the result is a set so it will contain no duplicates (based on <code>E.equals()</code>). * @precondition iterable != null/*w w w . j av a 2 s. co m*/ * @postcondition result != null */ public static <E> Set<E> unionAll(Iterable<? extends Collection<? extends E>> iterable) { final Set<E> result = new HashSet<E>(); for (Collection<? extends E> coll : iterable) { result.addAll(coll); } assert result != null; return result; }
From source file:Main.java
/** * Given two collections of elements of type <T>, return a collection containing the items from both lists * /*w w w . j a v a 2 s . c o m*/ * @param <T> * Type * @param collection1 * Collection #1 * @param collection2 * Collection #2 * @return Collection with items from both lists */ public static <T> Collection<T> union(Collection<? extends T> collection1, Collection<? extends T> collection2) { if (isEmpty(collection1)) { if (isEmpty(collection2)) { // if both are empty, return empty list return Collections.emptyList(); } // if just 1 is empty, return 2 return new ArrayList<T>(collection2); } // at this point when know 1 is not empty if (isEmpty(collection2)) { // so if 2 is, return 1. return new ArrayList<T>(collection1); } // we know both 1 and 2 aren't empty Set<T> union = new HashSet<T>(collection1.size() + collection2.size()); union.addAll(collection1); union.addAll(collection2); return new ArrayList<T>(union); }
From source file:Main.java
/** * Returns a {@link Collection} containing the union of the given * {@link Collection}s.//from w w w .ja va2 s . co m * <p> * The cardinality of each element in the returned {@link Collection} will * be equal to the maximum of the cardinality of that element in the two * given {@link Collection}s. * * @see Collection#addAll */ 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 HashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { 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:com.bstek.dorado.util.clazz.ClassUtils.java
public static Set<Class<?>> findClassTypes(String[] expressions, Class<?> targetType) throws IOException, ClassNotFoundException { Set<Class<?>> classTypes = new HashSet<Class<?>>(); for (String expression : expressions) { classTypes.addAll(findClassTypes(expression, targetType)); }//from w w w .j ava2 s. c o m return classTypes; }
From source file:edu.berkeley.nwbqueryengine.util.ValuesUtil.java
public static List<NwbResult> removeDuplicities(List<NwbResult> input) { List<NwbResult> al = new ArrayList<>(input); Set<NwbResult> hs = new HashSet<>(); hs.addAll(al); al.clear();/*w w w . j a va 2 s.co m*/ al.addAll(hs); return al; }