List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:Main.java
public static void logOutUser(Context context, String userId) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Set<String> currentUsers = prefs.getStringSet(LOGGED_IN_USER_PREFERENCE_KEY, new HashSet<>()); currentUsers.remove(userId);/*from w ww . j av a 2 s. co m*/ PreferenceManager.getDefaultSharedPreferences(context).edit() .putStringSet(LOGGED_IN_USER_PREFERENCE_KEY, currentUsers).commit(); }
From source file:Main.java
/** * Returns album IDs containing at least one cached track. * @return Albums IDs/*from w w w . j a v a 2 s. co m*/ */ public static Set<String> getCachedAlbumSet() { File cacheDir = getMusicCacheDir(); File[] albumList = cacheDir.listFiles(); Set<String> output = new HashSet<>(); for (File album : albumList) { if (album.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return filename.endsWith(".complete"); } }).length > 0) { output.add(album.getName()); } } return output; }
From source file:Main.java
public static Set getAllRunningService(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF); Set<String> names = new HashSet<>(); if (infos == null || infos.size() == 0) return null; for (RunningServiceInfo info : infos) { names.add(info.service.getClassName()); }/*from w w w.j av a 2 s. c om*/ return names; }
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 ww.j av a 2s . co m } } return resultList; }
From source file:Main.java
/** * Returns all objects in list1 that are not in list2 * * @param <T> Type of items in the collection * @param list1 First collection/*www . j a v a2 s . co m*/ * @param list2 Second collection * @return The collection difference list1 - list2 */ public static <T> Set<T> diffAsSet(Collection<T> list1, Collection<T> list2) { Set<T> diff = new HashSet<T>(); for (T t : list1) { if (!list2.contains(t)) { diff.add(t); } } return diff; }
From source file:Main.java
/** * Returns the slot pattern. // w w w. j a v a2 s . c om * * Start slot Block size Increment * 0 5 25 * 10 5 25 * 18 4 25 * @return */ private static Set<String> getFATDMASlotPattern() { if (FATDMASlotPattern == null) { FATDMASlotPattern = new HashSet<String>(); for (int startSlot = 0; startSlot <= 2500; startSlot += 25) { for (int i = 0; i <= 4; ++i) { int slot = startSlot + i; FATDMASlotPattern.add(slot + ""); } } for (int startSlot = 10; startSlot <= 2500; startSlot += 25) { for (int i = 0; i <= 4; ++i) { int slot = startSlot + i; FATDMASlotPattern.add(slot + ""); } } for (int startSlot = 18; startSlot <= 2500; startSlot += 25) { for (int i = 0; i <= 3; ++i) { int slot = startSlot + i; FATDMASlotPattern.add(slot + ""); } } return FATDMASlotPattern; } else { return FATDMASlotPattern; } }
From source file:Main.java
public static Set<String> split(String string, String separator) { Set<String> set = new HashSet<String>(); if (string == null) return set; String[] split = string.split(separator); for (String v : split) set.add(v.trim());/*from ww w . j a v a 2s.c o m*/ return set; }
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:Main.java
/** * Get all threads/*w w w .ja va 2s. c om*/ * * @return */ public static String[] getThreadNames() { ThreadGroup group = Thread.currentThread().getThreadGroup(); ThreadGroup parent = null; while ((parent = group.getParent()) != null) { group = parent; } Thread[] threads = new Thread[group.activeCount()]; group.enumerate(threads); HashSet<String> set = new HashSet<String>(); for (int i = 0; i < threads.length; ++i) { if (threads[i] != null && threads[i].isAlive()) { try { set.add(threads[i].getThreadGroup().getName() + ", " + threads[i].getName() + ", " + threads[i].getPriority() + ", " + threads[i].getState()); } catch (Throwable e) { e.printStackTrace(); } } } String[] result = (String[]) set.toArray(new String[0]); Arrays.sort(result); for (int i = 0; i < result.length; i++) { // logger.debug(result[i]); } return result; }
From source file:Main.java
private static <T> Collection<T> newCollection(Collection<T> coll) { try {//from w w w . j a va 2 s . co m Class cl = coll.getClass(); Constructor con = cl.getConstructor(new Class[0]); return (Collection<T>) con.newInstance(new Object[0]); } catch (Exception e) { if (coll instanceof List) return new LinkedList<T>(); if (coll instanceof Set) return new HashSet<T>(); throw new RuntimeException("Cannot handle this collection"); } }