List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
From source file:Main.java
/** * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has * the specified initial capacity and default load factor (0.75). * /*w w w.ja va2 s. c o m*/ * @param <T> * @param initialCapacity * @return */ public static <T> Set<T> newHashSet(int initialCapacity) { return new HashSet<T>(initialCapacity); }
From source file:Main.java
public static void setComponentTraversalKeys(int direction, JComponent component, KeyStroke stroke) { Set<AWTKeyStroke> forwardKeys = component.getFocusTraversalKeys(direction); Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys); newForwardKeys.add(stroke);// www. j av a 2 s . co m component.setFocusTraversalKeys(direction, newForwardKeys); }
From source file:Main.java
/** * Returns union of two collections.// w w w . jav a 2 s . c o m * * @param <T> the generic type * @param coll1 the coll1 * @param coll2 the coll2 * @return the collection */ public static <T> Collection<T> union(Collection<T> coll1, Collection<T> coll2) { Set<T> union = new HashSet<T>(coll1); union.addAll(new HashSet<T>(coll2)); return union; }
From source file:Main.java
public static <T> Set<T> asSet(T... ts) { HashSet<T> set = new HashSet<T>(ts.length); Collections.addAll(set, ts);//from w w w . j a v a 2 s . c om return set; }
From source file:Main.java
/** * Returns intersection of two collections. * * @param <T> the generic type//from w w w . j a v a2 s . c om * @param coll1 the coll1 * @param coll2 the coll2 * @return the collection */ public static <T> Collection<T> intersect(Collection<T> coll1, Collection<T> coll2) { Set<T> intersection = new HashSet<T>(coll1); intersection.retainAll(new HashSet<T>(coll2)); return intersection; }
From source file:Main.java
/** * Convert to Set - this operation removes the duplicates in original list. * @param list//from www . j a v a 2 s . com * @return */ public static <T> Set<T> converToSet(List<T> list) { if (list == null || list.isEmpty()) { return Collections.emptySet(); } return new HashSet<T>(list); }
From source file:Main.java
public static Map<Integer, Set<Class<?>>> simpleParameterClasses(final Class<?>... classes) { final Map<Integer, Set<Class<?>>> res = new HashMap<>(classes.length); for (int i = 0; i < classes.length; i++) { final Set<Class<?>> set = new HashSet<>(1); set.add(classes[i]);//from w w w . ja va2 s. c o m res.put(i, set); } return res; }
From source file:Main.java
public static <T> Set<T> asSet(T[] a_array) /* */ {//www . j a v a 2s . com /* 298 */if (a_array == null) /* */ { /* 300 */return null; /* */} /* */ /* 304 */List list = Arrays.asList(a_array); /* 305 */return new HashSet(list); /* */}
From source file:Main.java
public static <T> Set<T> getSet(Collection<T> collection) { return new HashSet<T>(collection); }
From source file:Main.java
public static <T> Set<T> asUnmodifiableSet(T[] a_array) /* */ {//from ww w .j ava 2 s . c om /* 318 */if (a_array == null) /* */ { /* 320 */return null; /* */} /* */ /* 324 */List list = Arrays.asList(a_array); /* 325 */Set set = new HashSet(list); /* 326 */return Collections.unmodifiableSet(set); /* */}