List of usage examples for java.util Set add
boolean add(E e);
From source file:Main.java
@SafeVarargs public static <V> Set<V> toSet(Set<V> s, V... elements) { for (V v : elements) { s.add(v); }//ww w . ja v a2 s . c o m return s; }
From source file:Main.java
/** * Adds several values to a set./* w w w . j av a 2 s .com*/ * * @param <T> * the set's element type. * @param set * the set. * @param values * the values to be added. * @return the given set. */ @SafeVarargs public static <T> Set<T> addToSet(final Set<T> set, final T... values) { for (final T t : values) { set.add(t); } return set; }
From source file:Main.java
/** * Get only the unique elements in a collection *//*from w ww . j a v a2 s. com*/ public static Set<?> getUniqueElements(Collection<?> items) { Set<Object> uniqueSet = new HashSet<>(); for (Object item : items) { uniqueSet.add(item); } return uniqueSet; }
From source file:Main.java
/** * Returns the set of all elements in the given collection that appear more than once. * @param input some collection.//w w w . java 2s. c om * @return the set of repeated elements. May return an empty set, but never null. */ public static <T> Set<T> duplicatedElementsOf(Iterable<T> input) { Set<T> duplicates = new HashSet<>(); Set<T> elementSet = new HashSet<>(); for (T el : input) { if (!elementSet.add(el)) { duplicates.add(el); } } return duplicates; }
From source file:Main.java
@Deprecated public static <T> Set<T> asSet(final T t, final T... ts) { final Set<T> set = new HashSet<T>(ts.length + 1); set.add(t); Collections.addAll(set, ts);/* w ww . j a v a 2s.c o m*/ return set; }
From source file:Main.java
public static void registerNewSourceSinkConnection(int counter, String taintInfoOfSource) { Log.i("PEP", "in registerNewSourceSinkConnection(int counter, String taintInfoOfSource)"); Set<String> taintInfos = new HashSet<String>(); taintInfos.add(taintInfoOfSource); sourceSinkConnection.put(counter, taintInfos); }
From source file:Main.java
/** * Convert an array into a <code>Set</code>. * @param <T> the type of the elements in the array. * @param array the array to convert./*from w w w .j a v a2 s . c o m*/ * @return a set of elements with the same type as that of the array element type. */ public static <T> Set<T> set(T... array) { Set<T> newSet = new HashSet<T>(); for (T element : array) newSet.add(element); return newSet; }
From source file:Main.java
public static Hashtable<Integer, Set<Integer>> getNodeMembership(Hashtable<Integer, Set<Integer>> nIDComVH, final Vector<Set<Integer>> cmtyVV) { for (int i = 0; i < cmtyVV.size(); i++) { int CID = i; for (Integer NID : cmtyVV.get(i)) { if (nIDComVH.containsKey(NID)) { Set<Integer> x = nIDComVH.get(NID); x.add(CID); } else { Set<Integer> x = new HashSet<Integer>(); x.add(CID);/* w ww . ja va 2 s . co m*/ nIDComVH.put(NID, x); } } } return nIDComVH; }
From source file:Main.java
public static Set<String> loadSet(SharedPreferences prefs, String setName) { final int size = prefs.getInt(setName + "_size", 0); Set<String> set = new HashSet<String>(size); for (int i = 0; i < size; i++) set.add(prefs.getString(setName + "_" + i, null)); return set;//from w w w .jav a2 s. c om }
From source file:Main.java
public static <T> LinkedHashSet<T> getDuplicates(final Iterable<T> iterable) { LinkedHashSet<T> duplicates = new LinkedHashSet<>(); Set<T> dupeChecker = new LinkedHashSet<>(); iterable.forEach((m) -> {//from w w w. jav a 2s. c om if (!dupeChecker.add(m)) { duplicates.add(m); } }); return duplicates; }