List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:Main.java
public static <T> Set<T> newHashSetOnNull(Set<T> set) { if (set == null) { set = new HashSet<T>(); }// ww w. ja v a 2 s . co m return set; }
From source file:Main.java
public static Set toSet(String... values) { Set<Object> set = new HashSet<>(); for (String value : values) { set.add(value);//from w ww . j a v a 2s. c o m } return set; }
From source file:Main.java
public static <T> Set<T> set(T... objects) { Set<T> set = new HashSet<T>(); for (T obj : objects) { set.add(obj);//from w w w . ja v a 2 s . c o m } return set; }
From source file:Main.java
public static String removeRepeat(String s) { Set<Object> tempSet = new HashSet<Object>(); String[] t = s.split(","); for (int i = 0; i < t.length; i++) { tempSet.add(t[i]);//from w ww . ja v a2 s . com } Object[] tempObject = tempSet.toArray(); String temp = ""; for (int i = 0; i < tempObject.length; i++) { temp += tempObject[i] + ","; } return temp; }
From source file:Main.java
public static Set<Class<?>> findSuperTypes(Class<?> targetClass) { Set<Class<?>> classes = new HashSet<Class<?>>(); Class<?> clazz = targetClass; while (clazz != null) { classes.add(clazz);/*from w w w . j a v a 2 s . c o m*/ addInterfaces(classes, clazz.getInterfaces()); clazz = clazz.getSuperclass(); } return classes; }
From source file:Main.java
public static <T> Set<T> extractIntersection(Set<T> left, Set<T> right) { Set<T> intersection = new HashSet<>(); for (T itemLeft : left) { for (T itemRight : right) { if (itemLeft.equals(itemRight)) { intersection.add(itemLeft); }//from ww w. j a v a 2 s . c o m } } return intersection; }
From source file:Main.java
/** * @param <T>// ww w . j ava2 s . c om * @param list * @return list */ public static <T> Set<T> list2Set(List<T> list) { Set<T> set = new HashSet<T>(); set.addAll(list); return set; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static HashSet filterHashSet(HashSet target) { if (null == target) { target = new HashSet(); }// w w w . java2 s .co m return target; }
From source file:Main.java
public static int[] divide(int number, int number_of_parts) { HashSet<Integer> uniqueInts = new HashSet<Integer>(); uniqueInts.add(0);//from www .jav a2s. c o m uniqueInts.add(number); int array_size = number_of_parts + 1; while (uniqueInts.size() < array_size) { uniqueInts.add(1 + r.nextInt(number - 1)); } Integer[] dividers = uniqueInts.toArray(new Integer[array_size]); Arrays.sort(dividers); int[] results = new int[number_of_parts]; for (int i = 1, j = 0; i < dividers.length; ++i, ++j) { results[j] = dividers[i] - dividers[j]; } return results; }
From source file:Main.java
/** A set with the given element.//from w w w. j a va 2 s . c o m */ public static <T> Set<T> a(T root) { Set<T> result = new HashSet<T>(); result.add(root); return result; }