List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:Main.java
public static Set<String> getAllFaceIds(String personId, Context context) { SharedPreferences faceIdSet = context.getSharedPreferences(personId + "FaceIdSet", Context.MODE_PRIVATE); return faceIdSet.getStringSet("FaceIdSet", new HashSet<String>()); }
From source file:Main.java
public static <T> Set<Class<T>> findClassesAssignableFrom(String packageName, Class<T> assignableFrom) throws IOException, ClassNotFoundException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Set<Class<T>> classes = new HashSet<Class<T>>(); String path = packageName.replace('.', '/'); URL resource = loader.getResource(path); if (resource != null) { String filePath = resource.getFile(); if (filePath != null && new File(filePath).isDirectory()) { for (String file : new File(filePath).list()) { if (file.endsWith(".class")) { String name = packageName + '.' + file.substring(0, file.indexOf(".class")); Class<T> clazz = (Class<T>) Class.forName(name); if (assignableFrom.isAssignableFrom(clazz)) classes.add(clazz); }/* w w w.j a v a 2 s .c om*/ } } } return classes; }
From source file:Main.java
public static Set<String> getLoggedInUsers(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getStringSet(LOGGED_IN_USER_PREFERENCE_KEY, new HashSet<>()); }
From source file:Main.java
/** * Select the given number of elements from the given set. * * @param <T> encapsulated type/*w w w. jav a 2 s.com*/ * @param set set * @param count number of elements to retrieve * @return set */ public static <T> Set<T> selectSome(Set<T> set, int count) { Set<T> newSet = new HashSet<T>(); int i = 0; for (T each : set) { if (++i > count) { break; } newSet.add(each); } return newSet; }
From source file:Main.java
/** * Turns a list of vararg parameters into a set. * * @param ts The vararg parameters./* ww w. j av a 2s. c o m*/ * @param <T> The type of the parameters. * * @return A set created by adding the parameters in the order presented into a set. */ public static <T> Set<T> paramsToSet(T... ts) { Set<T> result = new HashSet<>(); Collections.addAll(result, ts); return result; }
From source file:Main.java
public static <T> HashSet<T> newHashSet(Collection<T> collection) { HashSet<T> set = new HashSet<T>(); set.addAll(collection);// w w w.j a v a 2 s. co m return set; }
From source file:Main.java
private static Collection getEmpty(Collection collection) { try {// w w w. j ava 2 s .c om return (Collection) collection.getClass().newInstance(); } catch (Exception e) { if (collection instanceof List) { return new ArrayList(); } else { return new HashSet(); } } }
From source file:Main.java
public static ArrayList<Double> stringToDoubleListRemoved(String s, String delimeter, int[] fieldsToBeRemoved) { ArrayList<Double> ret = new ArrayList<Double>(); ArrayList<Double> allFields = stringToDoubleList(s, delimeter); HashSet<Integer> toBeRemoved = new HashSet<Integer>(); for (int i : fieldsToBeRemoved) toBeRemoved.add(i);/*w ww. j ava 2 s . c o m*/ for (int i = 0; i < allFields.size(); i++) { if (toBeRemoved.contains(i)) continue; ret.add(allFields.get(i)); } return ret; }
From source file:Main.java
public static Set<String> getExpectedDoorNames() { Set<String> expectedDoors = new HashSet<>(); expectedDoors.add(DOOR1_NAME);//w w w . ja v a 2 s.c o m expectedDoors.add(DOOR2_NAME); expectedDoors.add(DOOR3_NAME); return expectedDoors; }
From source file:Main.java
public static Set<String> getAllPersonIds(String personGroupId, Context context) { SharedPreferences personIdSet = context.getSharedPreferences(personGroupId + "PersonIdSet", Context.MODE_PRIVATE); return personIdSet.getStringSet("PersonIdSet", new HashSet<String>()); }