List of usage examples for java.util Set add
boolean add(E e);
From source file:Main.java
public static <T> Set<T> intersect(final Collection<? extends T> c1, final Collection<? extends T> c2) { final Set<T> set = new HashSet<T>(); for (T t : c1) { if (c2.contains(t)) set.add(t); }//from www. j a v a 2 s .co m return set; }
From source file:Main.java
/** * Converts the given objects into a {@link Set}. * @param <T> The type of the objects. * @param objects The objects array to convert. * @return The created {@link Set}.// w w w. j a v a 2s . co m */ public static <T> Set<T> toSet(T... objects) { if (objects != null) { Set<T> result = new LinkedHashSet<T>(objects.length); for (T obj : objects) { result.add(obj); } return result; } else { return new LinkedHashSet<T>(0); } }
From source file:Main.java
/** * Converts parameters into a set//from ww w . ja v a 2 s . co m * * @param <T> set element type * @param first element * @param second element * @param third element * @param rest elements * @return set containing the given elements */ @SafeVarargs public static <T> Set<T> asSet(T first, T second, T third, T... rest) { Set<T> set = new HashSet<>(Arrays.asList(rest)); set.add(first); set.add(second); set.add(third); return set; }
From source file:Main.java
public static Set<Integer> getIntersection(Set<Integer> set1, Set<Integer> set2) { Set<Integer> ret = new HashSet<Integer>(); for (Integer i : set1) { if (set2.contains(i)) { ret.add(i); }/* w w w.j a v a 2s. c om*/ } return ret; }
From source file:Main.java
public static void addToFavorites(final Context context, long movieId) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Set<String> set = sp.getStringSet(PREF_FAVORED_MOVIES, null); if (set == null) set = new HashSet<>(); set.add(String.valueOf(movieId)); sp.edit().putStringSet(PREF_FAVORED_MOVIES, set).apply(); }
From source file:io.github.jeddict.orm.generator.compiler.GeneratedValueSnippet.java
private static Set<String> getStrategyTypes() { Set<String> strategyTypes = new HashSet<>(); strategyTypes.add(AUTO); strategyTypes.add(IDENTITY);/*from w ww . ja v a2 s .c o m*/ strategyTypes.add(SEQUENCE); strategyTypes.add(TABLE); return strategyTypes; }
From source file:Main.java
public static void setPersonName(String personIdToAdd, String personName, String personGroupId, Context context) {/*from w w w .j av a2 s . com*/ SharedPreferences personIdNameMap = context.getSharedPreferences(personGroupId + "PersonIdNameMap", Context.MODE_PRIVATE); SharedPreferences.Editor personIdNameMapEditor = personIdNameMap.edit(); personIdNameMapEditor.putString(personIdToAdd, personName); personIdNameMapEditor.commit(); Set<String> personIds = getAllPersonIds(personGroupId, context); Set<String> newPersonIds = new HashSet<>(); for (String personId : personIds) { newPersonIds.add(personId); } newPersonIds.add(personIdToAdd); SharedPreferences personIdSet = context.getSharedPreferences(personGroupId + "PersonIdSet", Context.MODE_PRIVATE); SharedPreferences.Editor personIdSetEditor = personIdSet.edit(); personIdSetEditor.putStringSet("PersonIdSet", newPersonIds); personIdSetEditor.commit(); }
From source file:Main.java
public static Set<Long> crossing(Set<Long> list1, Set<Long> list2) { Set<Long> resultList = new HashSet(); for (Long l : list1) { if (list2.contains(l)) { resultList.add(l); }/* w w w . j a v a 2 s.co m*/ } return resultList; }
From source file:Main.java
private static <K, T> void add(Map<K, Set<T>> map, K key, T val) { Set<T> n = map.get(key); if (null == n) { n = new LinkedHashSet<T>(); map.put(key, n);/*from w w w. j av a 2 s.co m*/ } n.add(val); }
From source file:com.stratio.decision.service.StreamsHelper.java
public static StratioStreamingMessage getSampleMessage() { Set<StreamAction> actions = new ListOrderedSet(); actions.add(StreamAction.LISTEN); StratioStreamingMessage message = new StratioStreamingMessage(STREAM_NAME, Long.parseLong("1234567890"), COLUMNS);//from w w w . ja v a 2 s . c o m message.setActiveActions(actions); return message; }