CollectionUtils { 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; }  static Map<K, V> newHashMap(); static Map<K, V> newLinkedHashMap(); static Set<K> newHashSet(); static Set<K> newLinkedHashSet(); static List<L> newArrayList(int size); static List<L> newArrayList(); static Map<K, V> buildMap(K key1, V value1); static Map<K, V> buildMap(K key1, V value1, K key2, V value2); static Map<K, V> buildMap(K key1, V value1, K key2, V value2, K key3, V value3); static Map<K, V> buildMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); static Map<K, V> buildMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5); static Set<T> selectSome(Set<T> set, int count); static HashMap<K, V> newHashMap(int size); static HashMap<K, V> newHashMap(Collection<?> base); static V getValue(Map<K, V> map, K key, V defaultValue);  }
@Test public void testSelectSome() { Set<Integer> intSet = new HashSet<Integer>(); intSet.add(1); intSet.add(2); intSet.add(3); intSet.add(4); intSet.add(5); intSet.add(6); Set<Integer> rtnSet = CollectionUtils.selectSome(intSet, 3); assertThat(rtnSet.size(), is(3)); assertTrue(rtnSet.contains(1)); assertTrue(rtnSet.contains(2)); assertTrue(rtnSet.contains(3)); }