target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testIsEmptyWithNonEmptyMap() { final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); map.put("item", "value"); assertEquals(false, MultiMapUtils.isEmpty(map)); }
public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); @SuppressWarnings({ "rawtypes", "unchecked" }) static final MultiValuedMap EMPTY_MULTI_VALUED_MAP; }
@Test public void testIsEmptyWithNull() { final MultiValuedMap<Object, Object> map = null; assertEquals(true, MultiMapUtils.isEmpty(map)); }
public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); }
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); @SuppressWarnings({ "rawtypes", "unchecked" }) static final MultiValuedMap EMPTY_MULTI_VALUED_MAP; }
@Test public void testGetCollection() { assertNull(MultiMapUtils.getCollection(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); } Collection<String> col = MultiMapUtils.getCollection(map, "key1"); for (String val : values) { assertTrue(col.contains(val)); } }
public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) { if (map != null) { return map.get(key); } return null; }
MultiMapUtils { public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) { if (map != null) { return map.get(key); } return null; } }
MultiMapUtils { public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) { if (map != null) { return map.get(key); } return null; } private MultiMapUtils(); }
MultiMapUtils { public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) { if (map != null) { return map.get(key); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); }
MultiMapUtils { public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) { if (map != null) { return map.get(key); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); @SuppressWarnings({ "rawtypes", "unchecked" }) static final MultiValuedMap EMPTY_MULTI_VALUED_MAP; }
@Test public void testGetValuesAsList() { assertNull(MultiMapUtils.getValuesAsList(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); } List<String> list = MultiMapUtils.getValuesAsList(map, "key1"); int i = 0; for (String val : list) { assertTrue(val.equals(values[i++])); } }
public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof List) { return (List<V>) col; } return new ArrayList<V>(col); } return null; }
MultiMapUtils { public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof List) { return (List<V>) col; } return new ArrayList<V>(col); } return null; } }
MultiMapUtils { public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof List) { return (List<V>) col; } return new ArrayList<V>(col); } return null; } private MultiMapUtils(); }
MultiMapUtils { public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof List) { return (List<V>) col; } return new ArrayList<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); }
MultiMapUtils { public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof List) { return (List<V>) col; } return new ArrayList<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); @SuppressWarnings({ "rawtypes", "unchecked" }) static final MultiValuedMap EMPTY_MULTI_VALUED_MAP; }
@Test public void testGetValuesAsSet() { assertNull(MultiMapUtils.getValuesAsList(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); map.put("key1", val); } Set<String> set = MultiMapUtils.getValuesAsSet(map, "key1"); assertEquals(3, set.size()); for (String val : values) { assertTrue(set.contains(val)); } }
public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Set) { return (Set<V>) col; } return new HashSet<V>(col); } return null; }
MultiMapUtils { public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Set) { return (Set<V>) col; } return new HashSet<V>(col); } return null; } }
MultiMapUtils { public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Set) { return (Set<V>) col; } return new HashSet<V>(col); } return null; } private MultiMapUtils(); }
MultiMapUtils { public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Set) { return (Set<V>) col; } return new HashSet<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); }
MultiMapUtils { public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Set) { return (Set<V>) col; } return new HashSet<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); @SuppressWarnings({ "rawtypes", "unchecked" }) static final MultiValuedMap EMPTY_MULTI_VALUED_MAP; }
@Test public void testGetValuesAsBag() { assertNull(MultiMapUtils.getValuesAsBag(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); map.put("key1", val); } Bag<String> bag = MultiMapUtils.getValuesAsBag(map, "key1"); assertEquals(6, bag.size()); for (String val : values) { assertTrue(bag.contains(val)); assertEquals(2, bag.getCount(val)); } }
public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Bag) { return (Bag<V>) col; } return new HashBag<V>(col); } return null; }
MultiMapUtils { public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Bag) { return (Bag<V>) col; } return new HashBag<V>(col); } return null; } }
MultiMapUtils { public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Bag) { return (Bag<V>) col; } return new HashBag<V>(col); } return null; } private MultiMapUtils(); }
MultiMapUtils { public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Bag) { return (Bag<V>) col; } return new HashBag<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); }
MultiMapUtils { public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Bag) { return (Bag<V>) col; } return new HashBag<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map); static boolean isEmpty(final MultiValuedMap<?, ?> map); static Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key); static List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key); static Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key); static Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key); static ListValuedMap<K, V> newListValuedHashMap(); static SetValuedMap<K, V> newSetValuedHashMap(); static MultiValuedMap<K, V> unmodifiableMultiValuedMap( final MultiValuedMap<? extends K, ? extends V> map); static MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map, final Transformer<? super K, ? extends K> keyTransformer, final Transformer<? super V, ? extends V> valueTransformer); @SuppressWarnings({ "rawtypes", "unchecked" }) static final MultiValuedMap EMPTY_MULTI_VALUED_MAP; }
@Test public void testUpdateReturnVoid() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Void> rt = TypeToken.of(void.class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "update user set name=? where id=?"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) "ash")); assertThat(args.get(1), equalTo((Object) 100)); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); Object r = operator.execute(new Object[]{user}, InvocationStat.create()); assertThat(r, nullValue()); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void testpredicatedSet() { final Predicate<Object> predicate = new Predicate<Object>() { @Override public boolean evaluate(final Object o) { return o instanceof String; } }; Set<Object> set = SetUtils.predicatedSet(new HashSet<Object>(), predicate); assertTrue("returned object should be a PredicatedSet", set instanceof PredicatedSet); try { SetUtils.predicatedSet(new HashSet<Object>(), null); fail("Expecting NullPointerException for null predicate."); } catch (final NullPointerException ex) { } try { SetUtils.predicatedSet(null, predicate); fail("Expecting NullPointerException for null set."); } catch (final NullPointerException ex) { } }
public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) { return PredicatedSet.predicatedSet(set, predicate); }
SetUtils { public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) { return PredicatedSet.predicatedSet(set, predicate); } }
SetUtils { public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) { return PredicatedSet.predicatedSet(set, predicate); } private SetUtils(); }
SetUtils { public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) { return PredicatedSet.predicatedSet(set, predicate); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) { return PredicatedSet.predicatedSet(set, predicate); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void testEmptyIfNull() { assertTrue(SetUtils.emptyIfNull(null).isEmpty()); final Set<Long> set = new HashSet<Long>(); assertSame(set, SetUtils.emptyIfNull(set)); }
public static <T> Set<T> emptyIfNull(final Set<T> set) { return set == null ? Collections.<T>emptySet() : set; }
SetUtils { public static <T> Set<T> emptyIfNull(final Set<T> set) { return set == null ? Collections.<T>emptySet() : set; } }
SetUtils { public static <T> Set<T> emptyIfNull(final Set<T> set) { return set == null ? Collections.<T>emptySet() : set; } private SetUtils(); }
SetUtils { public static <T> Set<T> emptyIfNull(final Set<T> set) { return set == null ? Collections.<T>emptySet() : set; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <T> Set<T> emptyIfNull(final Set<T> set) { return set == null ? Collections.<T>emptySet() : set; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void testEquals() { final Collection<String> data = Arrays.asList("a", "b", "c"); final Set<String> a = new HashSet<String>(data); final Set<String> b = new HashSet<String>(data); assertEquals(true, a.equals(b)); assertEquals(true, SetUtils.isEqualSet(a, b)); a.clear(); assertEquals(false, SetUtils.isEqualSet(a, b)); assertEquals(false, SetUtils.isEqualSet(a, null)); assertEquals(false, SetUtils.isEqualSet(null, b)); assertEquals(true, SetUtils.isEqualSet(null, null)); }
public static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2) { if (set1 == set2) { return true; } if (set1 == null || set2 == null || set1.size() != set2.size()) { return false; } return set1.containsAll(set2); }
SetUtils { public static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2) { if (set1 == set2) { return true; } if (set1 == null || set2 == null || set1.size() != set2.size()) { return false; } return set1.containsAll(set2); } }
SetUtils { public static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2) { if (set1 == set2) { return true; } if (set1 == null || set2 == null || set1.size() != set2.size()) { return false; } return set1.containsAll(set2); } private SetUtils(); }
SetUtils { public static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2) { if (set1 == set2) { return true; } if (set1 == null || set2 == null || set1.size() != set2.size()) { return false; } return set1.containsAll(set2); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2) { if (set1 == set2) { return true; } if (set1 == null || set2 == null || set1.size() != set2.size()) { return false; } return set1.containsAll(set2); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void testHashCode() { final Collection<String> data = Arrays.asList("a", "b", "c"); final Set<String> a = new HashSet<String>(data); final Set<String> b = new HashSet<String>(data); assertEquals(true, a.hashCode() == b.hashCode()); assertEquals(true, a.hashCode() == SetUtils.hashCodeForSet(a)); assertEquals(true, b.hashCode() == SetUtils.hashCodeForSet(b)); assertEquals(true, SetUtils.hashCodeForSet(a) == SetUtils.hashCodeForSet(b)); a.clear(); assertEquals(false, SetUtils.hashCodeForSet(a) == SetUtils.hashCodeForSet(b)); assertEquals(0, SetUtils.hashCodeForSet(null)); }
public static <T> int hashCodeForSet(final Collection<T> set) { if (set == null) { return 0; } int hashCode = 0; for (final T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } } return hashCode; }
SetUtils { public static <T> int hashCodeForSet(final Collection<T> set) { if (set == null) { return 0; } int hashCode = 0; for (final T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } } return hashCode; } }
SetUtils { public static <T> int hashCodeForSet(final Collection<T> set) { if (set == null) { return 0; } int hashCode = 0; for (final T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } } return hashCode; } private SetUtils(); }
SetUtils { public static <T> int hashCodeForSet(final Collection<T> set) { if (set == null) { return 0; } int hashCode = 0; for (final T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } } return hashCode; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <T> int hashCodeForSet(final Collection<T> set) { if (set == null) { return 0; } int hashCode = 0; for (final T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } } return hashCode; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void testNewIdentityHashSet() { Set<String> set = SetUtils.newIdentityHashSet(); String a = new String("a"); set.add(a); set.add(new String("b")); set.add(a); assertEquals(2, set.size()); set.add(new String("a")); assertEquals(3, set.size()); set.remove(a); assertEquals(2, set.size()); }
public static <E> Set<E> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); }
SetUtils { public static <E> Set<E> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); } }
SetUtils { public static <E> Set<E> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); } private SetUtils(); }
SetUtils { public static <E> Set<E> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> Set<E> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void union() { final SetView<Integer> set = SetUtils.union(setA, setB); assertEquals(7, set.size()); assertTrue(set.containsAll(setA)); assertTrue(set.containsAll(setB)); final Set<Integer> set2 = SetUtils.union(setA, SetUtils.<Integer>emptySet()); assertEquals(setA, set2); try { SetUtils.union(setA, null); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } try { SetUtils.union(null, setA); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } }
public static <E> SetView<E> union(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) || b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(a.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return a.isEmpty() && b.isEmpty(); } @Override public int size() { return a.size() + bMinusA.size(); } }; }
SetUtils { public static <E> SetView<E> union(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) || b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(a.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return a.isEmpty() && b.isEmpty(); } @Override public int size() { return a.size() + bMinusA.size(); } }; } }
SetUtils { public static <E> SetView<E> union(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) || b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(a.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return a.isEmpty() && b.isEmpty(); } @Override public int size() { return a.size() + bMinusA.size(); } }; } private SetUtils(); }
SetUtils { public static <E> SetView<E> union(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) || b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(a.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return a.isEmpty() && b.isEmpty(); } @Override public int size() { return a.size() + bMinusA.size(); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> SetView<E> union(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) || b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(a.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return a.isEmpty() && b.isEmpty(); } @Override public int size() { return a.size() + bMinusA.size(); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void difference() { final SetView<Integer> set = SetUtils.difference(setA, setB); assertEquals(2, set.size()); assertTrue(set.contains(1)); assertTrue(set.contains(2)); for (Integer i : setB) { assertFalse(set.contains(i)); } final Set<Integer> set2 = SetUtils.difference(setA, SetUtils.<Integer>emptySet()); assertEquals(setA, set2); try { SetUtils.difference(setA, null); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } try { SetUtils.difference(null, setA); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } }
public static <E> SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> notContainedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return !b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && !b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), notContainedInB); } }; }
SetUtils { public static <E> SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> notContainedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return !b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && !b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), notContainedInB); } }; } }
SetUtils { public static <E> SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> notContainedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return !b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && !b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), notContainedInB); } }; } private SetUtils(); }
SetUtils { public static <E> SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> notContainedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return !b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && !b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), notContainedInB); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> notContainedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return !b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && !b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), notContainedInB); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void intersection() { final SetView<Integer> set = SetUtils.intersection(setA, setB); assertEquals(3, set.size()); assertTrue(set.contains(3)); assertTrue(set.contains(4)); assertTrue(set.contains(5)); assertFalse(set.contains(1)); assertFalse(set.contains(2)); assertFalse(set.contains(6)); assertFalse(set.contains(7)); final Set<Integer> set2 = SetUtils.intersection(setA, SetUtils.<Integer>emptySet()); assertEquals(SetUtils.<Integer>emptySet(), set2); try { SetUtils.intersection(setA, null); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } try { SetUtils.intersection(null, setA); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } }
public static <E> SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> containedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), containedInB); } }; }
SetUtils { public static <E> SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> containedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), containedInB); } }; } }
SetUtils { public static <E> SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> containedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), containedInB); } }; } private SetUtils(); }
SetUtils { public static <E> SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> containedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), containedInB); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> containedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return b.contains(object); } }; return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) && b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.filteredIterator(a.iterator(), containedInB); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void disjunction() { final SetView<Integer> set = SetUtils.disjunction(setA, setB); assertEquals(4, set.size()); assertTrue(set.contains(1)); assertTrue(set.contains(2)); assertTrue(set.contains(6)); assertTrue(set.contains(7)); assertFalse(set.contains(3)); assertFalse(set.contains(4)); assertFalse(set.contains(5)); final Set<Integer> set2 = SetUtils.disjunction(setA, SetUtils.<Integer>emptySet()); assertEquals(setA, set2); try { SetUtils.disjunction(setA, null); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } try { SetUtils.disjunction(null, setA); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } }
public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } private SetUtils(); }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set, final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set, final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes") static final SortedSet EMPTY_SORTED_SET; }
@Test public void testExceptionFactory() { assertNotNull(FactoryUtils.exceptionFactory()); assertSame(FactoryUtils.exceptionFactory(), FactoryUtils.exceptionFactory()); try { FactoryUtils.exceptionFactory().create(); } catch (final FunctorException ex) { try { FactoryUtils.exceptionFactory().create(); } catch (final FunctorException ex2) { return; } } fail(); }
public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); }
FactoryUtils { public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); } }
FactoryUtils { public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testUpdateReturnBoolean() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Boolean> rt = TypeToken.of(boolean.class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "update user set name=? where id=?"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) "ash")); assertThat(args.get(1), equalTo((Object) 100)); return 0; } }); User user = new User(); user.setId(100); user.setName("ash"); boolean r = (Boolean) operator.execute(new Object[]{user}, InvocationStat.create()); assertThat(r, is(false)); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void testNullFactory() { final Factory<Object> factory = FactoryUtils.nullFactory(); assertNotNull(factory); final Object created = factory.create(); assertNull(created); }
public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); }
FactoryUtils { public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); } }
FactoryUtils { public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testConstantFactoryNull() { final Factory<Object> factory = FactoryUtils.constantFactory(null); assertNotNull(factory); final Object created = factory.create(); assertNull(created); }
public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testConstantFactoryConstant() { final Integer constant = Integer.valueOf(9); final Factory<Integer> factory = FactoryUtils.constantFactory(constant); assertNotNull(factory); final Integer created = factory.create(); assertSame(constant, created); }
public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testPrototypeFactoryNull() { assertSame(ConstantFactory.NULL_INSTANCE, FactoryUtils.prototypeFactory(null)); }
public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testPrototypeFactoryPublicCloneMethod() throws Exception { final Date proto = new Date(); final Factory<Date> factory = FactoryUtils.prototypeFactory(proto); assertNotNull(factory); final Date created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); }
public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testPrototypeFactoryPublicCopyConstructor() throws Exception { final Mock1 proto = new Mock1(6); Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto); assertNotNull(factory); final Object created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); }
public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testPrototypeFactoryPublicSerialization() throws Exception { final Integer proto = Integer.valueOf(9); final Factory<Integer> factory = FactoryUtils.prototypeFactory(proto); assertNotNull(factory); final Integer created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); }
public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testPrototypeFactoryPublicSerializationError() { final Mock2 proto = new Mock2(new Object()); final Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto); assertNotNull(factory); try { factory.create(); } catch (final FunctorException ex) { assertTrue(ex.getCause() instanceof IOException); return; } fail(); }
public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testPrototypeFactoryPublicBad() { final Object proto = new Object(); try { FactoryUtils.prototypeFactory(proto); } catch (final IllegalArgumentException ex) { return; } fail(); }
public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test(expected=NullPointerException.class) public void instantiateFactoryNull() { FactoryUtils.instantiateFactory(null); }
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void testUpdateReturnGeneratedIdInt() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Integer> rt = TypeToken.of(int.class); String srcSql = "insert into user(id, name) values(:1.id, :1.name)"; AbstractOperator operator = getOperatorReturnGeneratedId(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql, GeneratedKeyHolder holder) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "insert into user(id, name) values(?, ?)"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) 100)); assertThat(args.get(1), equalTo((Object) "ash")); assertThat(holder.getTypeHandler().getClass().equals(IntegerTypeHandler.class), is(true)); holder.setKey(100); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); Object r = operator.execute(new Object[]{user}, InvocationStat.create()); assertThat(r.getClass().equals(Integer.class), is(true)); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void instantiateFactorySimple() { final Factory<Mock3> factory = FactoryUtils.instantiateFactory(Mock3.class); assertNotNull(factory); Mock3 created = factory.create(); assertEquals(0, created.getValue()); created = factory.create(); assertEquals(1, created.getValue()); }
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test(expected=IllegalArgumentException.class) public void instantiateFactoryMismatch() { FactoryUtils.instantiateFactory(Date.class, null, new Object[] {null}); }
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test(expected=IllegalArgumentException.class) public void instantiateFactoryNoConstructor() { FactoryUtils.instantiateFactory(Date.class, new Class[] {Long.class}, new Object[] {null}); }
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void instantiateFactoryComplex() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); final Factory<Date> factory = FactoryUtils.instantiateFactory(Date.class, new Class[] {Integer.TYPE, Integer.TYPE, Integer.TYPE}, new Object[] {Integer.valueOf(70), Integer.valueOf(0), Integer.valueOf(2)}); assertNotNull(factory); final Date created = factory.create(); assertEquals(new Date(1000 * 60 * 60 * 24), created); }
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype); static Factory<T> instantiateFactory(final Class<T> classToInstantiate); static Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args); }
@Test public void booleanComparator() { Comparator<Boolean> comp = ComparatorUtils.booleanComparator(true); assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) < 0); assertTrue(comp.compare(Boolean.TRUE, Boolean.TRUE) == 0); assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) > 0); comp = ComparatorUtils.booleanComparator(false); assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) > 0); assertTrue(comp.compare(Boolean.TRUE, Boolean.TRUE) == 0); assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) < 0); }
public static Comparator<Boolean> booleanComparator(final boolean trueFirst) { return BooleanComparator.booleanComparator(trueFirst); }
ComparatorUtils { public static Comparator<Boolean> booleanComparator(final boolean trueFirst) { return BooleanComparator.booleanComparator(trueFirst); } }
ComparatorUtils { public static Comparator<Boolean> booleanComparator(final boolean trueFirst) { return BooleanComparator.booleanComparator(trueFirst); } private ComparatorUtils(); }
ComparatorUtils { public static Comparator<Boolean> booleanComparator(final boolean trueFirst) { return BooleanComparator.booleanComparator(trueFirst); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { public static Comparator<Boolean> booleanComparator(final boolean trueFirst) { return BooleanComparator.booleanComparator(trueFirst); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation static final Comparator NATURAL_COMPARATOR; }
@Test public void chainedComparator() { Comparator<Integer> comp = ComparatorUtils.chainedComparator(ComparatorUtils.<Integer>naturalComparator(), ComparatorUtils.<Integer>naturalComparator()); assertTrue(comp.compare(1, 2) < 0); assertTrue(comp.compare(1, 1) == 0); assertTrue(comp.compare(2, 1) > 0); }
public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) { final ComparatorChain<E> chain = new ComparatorChain<E>(); for (final Comparator<E> comparator : comparators) { if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } chain.addComparator(comparator); } return chain; }
ComparatorUtils { public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) { final ComparatorChain<E> chain = new ComparatorChain<E>(); for (final Comparator<E> comparator : comparators) { if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } chain.addComparator(comparator); } return chain; } }
ComparatorUtils { public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) { final ComparatorChain<E> chain = new ComparatorChain<E>(); for (final Comparator<E> comparator : comparators) { if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } chain.addComparator(comparator); } return chain; } private ComparatorUtils(); }
ComparatorUtils { public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) { final ComparatorChain<E> chain = new ComparatorChain<E>(); for (final Comparator<E> comparator : comparators) { if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } chain.addComparator(comparator); } return chain; } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) { final ComparatorChain<E> chain = new ComparatorChain<E>(); for (final Comparator<E> comparator : comparators) { if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } chain.addComparator(comparator); } return chain; } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation static final Comparator NATURAL_COMPARATOR; }
@Test public void max() { Comparator<Integer> reversed = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); assertEquals(Integer.valueOf(10), ComparatorUtils.max(1, 10, null)); assertEquals(Integer.valueOf(10), ComparatorUtils.max(10, -10, null)); assertEquals(Integer.valueOf(1), ComparatorUtils.max(1, 10, reversed)); assertEquals(Integer.valueOf(-10), ComparatorUtils.max(10, -10, reversed)); try { ComparatorUtils.max(1, null, null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } try { ComparatorUtils.max(null, 10, null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
@SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private ComparatorUtils(); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation static final Comparator NATURAL_COMPARATOR; }
@Test public void min() { Comparator<Integer> reversed = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); assertEquals(Integer.valueOf(1), ComparatorUtils.min(1, 10, null)); assertEquals(Integer.valueOf(-10), ComparatorUtils.min(10, -10, null)); assertEquals(Integer.valueOf(10), ComparatorUtils.min(1, 10, reversed)); assertEquals(Integer.valueOf(10), ComparatorUtils.min(10, -10, reversed)); try { ComparatorUtils.min(1, null, null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } try { ComparatorUtils.min(null, 10, null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
@SuppressWarnings("unchecked") public static <E> E min(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c < 0 ? o1 : o2; }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E min(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c < 0 ? o1 : o2; } }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E min(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c < 0 ? o1 : o2; } private ComparatorUtils(); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E min(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c < 0 ? o1 : o2; } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E min(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c < 0 ? o1 : o2; } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation static final Comparator NATURAL_COMPARATOR; }
@Test public void nullLowComparator() { Comparator<Integer> comp = ComparatorUtils.nullLowComparator(null); assertTrue(comp.compare(null, 10) < 0); assertTrue(comp.compare(null, null) == 0); assertTrue(comp.compare(10, null) > 0); }
@SuppressWarnings("unchecked") public static <E> Comparator<E> nullLowComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, false); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullLowComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, false); } }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullLowComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, false); } private ComparatorUtils(); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullLowComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, false); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullLowComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, false); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation static final Comparator NATURAL_COMPARATOR; }
@Test public void nullHighComparator() { Comparator<Integer> comp = ComparatorUtils.nullHighComparator(null); assertTrue(comp.compare(null, 10) > 0); assertTrue(comp.compare(null, null) == 0); assertTrue(comp.compare(10, null) < 0); }
@SuppressWarnings("unchecked") public static <E> Comparator<E> nullHighComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, true); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullHighComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, true); } }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullHighComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, true); } private ComparatorUtils(); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullHighComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, true); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullHighComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, true); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator, final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation static final Comparator NATURAL_COMPARATOR; }
@Test public void testUpdateReturnGeneratedIdLong() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Long> rt = TypeToken.of(long.class); String srcSql = "insert into user(id, name) values(:1.id, :1.name)"; AbstractOperator operator = getOperatorReturnGeneratedId(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql, GeneratedKeyHolder holder) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "insert into user(id, name) values(?, ?)"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) 100)); assertThat(args.get(1), equalTo((Object) "ash")); System.out.println(holder.getTypeHandler()); assertThat(holder.getTypeHandler().getClass().equals(LongTypeHandler.class), is(true)); holder.setKey(100L); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); Object r = operator.execute(new Object[]{user}, InvocationStat.create()); assertThat(r.getClass().equals(Long.class), is(true)); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void testAsIterable() { final List<Integer> list = new ArrayList<Integer>(); list.add(Integer.valueOf(0)); list.add(Integer.valueOf(1)); list.add(Integer.valueOf(2)); final Iterator<Integer> iterator = list.iterator(); final Iterable<Integer> iterable = IteratorUtils.asIterable(iterator); int expected = 0; for(final Integer actual : iterable) { assertEquals(expected, actual.intValue()); ++expected; } assertTrue(expected > 0); assertFalse("should not be able to iterate twice", IteratorUtils.asIterable(iterator).iterator().hasNext()); }
public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testAsIterableNull() { try { IteratorUtils.asIterable(null); fail("Expecting NullPointerException"); } catch (final NullPointerException ex) { } }
public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testAsMultipleIterable() { final List<Integer> list = new ArrayList<Integer>(); list.add(Integer.valueOf(0)); list.add(Integer.valueOf(1)); list.add(Integer.valueOf(2)); final Iterator<Integer> iterator = list.iterator(); final Iterable<Integer> iterable = IteratorUtils.asMultipleUseIterable(iterator); int expected = 0; for(final Integer actual : iterable) { assertEquals(expected, actual.intValue()); ++expected; } assertTrue(expected > 0); expected = 0; for(final Integer actual : iterable) { assertEquals(expected, actual.intValue()); ++expected; } assertTrue(expected > 0); }
public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testAsMultipleIterableNull() { try { IteratorUtils.asMultipleUseIterable(null); fail("Expecting NullPointerException"); } catch (final NullPointerException ex) { } }
public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testToList() { final List<Object> list = new ArrayList<Object>(); list.add(Integer.valueOf(1)); list.add("Two"); list.add(null); final List<Object> result = IteratorUtils.toList(list.iterator()); assertEquals(list, result); }
public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); }
IteratorUtils { public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); } }
IteratorUtils { public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); } private IteratorUtils(); }
IteratorUtils { public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testToArray() { final List<Object> list = new ArrayList<Object>(); list.add(Integer.valueOf(1)); list.add("Two"); list.add(null); final Object[] result = IteratorUtils.toArray(list.iterator()); assertEquals(list, Arrays.asList(result)); }
public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testToArray2() { final List<String> list = new ArrayList<String>(); list.add("One"); list.add("Two"); list.add(null); final String[] result = IteratorUtils.toArray(list.iterator(), String.class); assertEquals(list, Arrays.asList(result)); }
public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testArrayIterator() { final Object[] objArray = {"a", "b", "c"}; ResettableIterator<Object> iterator = IteratorUtils.arrayIterator(objArray); assertTrue(iterator.next().equals("a")); assertTrue(iterator.next().equals("b")); iterator.reset(); assertTrue(iterator.next().equals("a")); try { iterator = IteratorUtils.arrayIterator(Integer.valueOf(0)); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } try { iterator = IteratorUtils.arrayIterator((Object[]) null); fail("Expecting NullPointerException"); } catch (final NullPointerException ex) { } iterator = IteratorUtils.arrayIterator(objArray, 1); assertTrue(iterator.next().equals("b")); try { iterator = IteratorUtils.arrayIterator(objArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayIterator(objArray, 3); assertTrue(!iterator.hasNext()); iterator.reset(); try { iterator = IteratorUtils.arrayIterator(objArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayIterator(objArray, 2, 3); assertTrue(iterator.next().equals("c")); try { iterator = IteratorUtils.arrayIterator(objArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayIterator(objArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayIterator(objArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } final int[] intArray = {0, 1, 2}; iterator = IteratorUtils.arrayIterator(intArray); assertTrue(iterator.next().equals(Integer.valueOf(0))); assertTrue(iterator.next().equals(Integer.valueOf(1))); iterator.reset(); assertTrue(iterator.next().equals(Integer.valueOf(0))); iterator = IteratorUtils.arrayIterator(intArray, 1); assertTrue(iterator.next().equals(Integer.valueOf(1))); try { iterator = IteratorUtils.arrayIterator(intArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayIterator(intArray, 3); assertTrue(!iterator.hasNext()); iterator.reset(); try { iterator = IteratorUtils.arrayIterator(intArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayIterator(intArray, 2, 3); assertTrue(iterator.next().equals(Integer.valueOf(2))); try { iterator = IteratorUtils.arrayIterator(intArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayIterator(intArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayIterator(intArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } }
public static <E> ResettableIterator<E> arrayIterator(final E... array) { return new ObjectArrayIterator<E>(array); }
IteratorUtils { public static <E> ResettableIterator<E> arrayIterator(final E... array) { return new ObjectArrayIterator<E>(array); } }
IteratorUtils { public static <E> ResettableIterator<E> arrayIterator(final E... array) { return new ObjectArrayIterator<E>(array); } private IteratorUtils(); }
IteratorUtils { public static <E> ResettableIterator<E> arrayIterator(final E... array) { return new ObjectArrayIterator<E>(array); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> ResettableIterator<E> arrayIterator(final E... array) { return new ObjectArrayIterator<E>(array); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testArrayListIterator() { final Object[] objArray = {"a", "b", "c", "d"}; ResettableListIterator<Object> iterator = IteratorUtils.arrayListIterator(objArray); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals("a")); assertTrue(iterator.previous().equals("a")); assertTrue(iterator.next().equals("a")); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals("b")); assertTrue(iterator.next().equals("c")); assertTrue(iterator.next().equals("d")); assertTrue(iterator.nextIndex() == 4); assertTrue(iterator.previousIndex() == 3); try { iterator = IteratorUtils.arrayListIterator(Integer.valueOf(0)); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } try { iterator = IteratorUtils.arrayListIterator((Object[]) null); fail("Expecting NullPointerException"); } catch (final NullPointerException ex) { } iterator = IteratorUtils.arrayListIterator(objArray, 1); assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals("b")); assertTrue(iterator.previousIndex() == 0); try { iterator = IteratorUtils.arrayListIterator(objArray, -1); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(objArray, 3); assertTrue(iterator.hasNext()); try { iterator.previous(); fail("Expecting NoSuchElementException."); } catch (final NoSuchElementException ex) { } try { iterator = IteratorUtils.arrayListIterator(objArray, 5); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(objArray, 2, 3); assertTrue(iterator.next().equals("c")); try { iterator = IteratorUtils.arrayListIterator(objArray, 2, 5); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(objArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(objArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } final int[] intArray = {0, 1, 2}; iterator = IteratorUtils.arrayListIterator(intArray); assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals(Integer.valueOf(0))); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals(Integer.valueOf(1))); assertTrue(iterator.previousIndex() == 1); assertTrue(iterator.nextIndex() == 2); assertTrue(iterator.previous().equals(Integer.valueOf(1))); assertTrue(iterator.next().equals(Integer.valueOf(1))); iterator = IteratorUtils.arrayListIterator(intArray, 1); assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals(Integer.valueOf(1))); assertTrue(iterator.previous().equals(Integer.valueOf(1))); assertTrue(iterator.next().equals(Integer.valueOf(1))); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals(Integer.valueOf(2))); assertTrue(iterator.previousIndex() == 1); assertTrue(iterator.nextIndex() == 2); assertTrue(iterator.previous().equals(Integer.valueOf(2))); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); try { iterator = IteratorUtils.arrayListIterator(intArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(intArray, 3); assertTrue(!iterator.hasNext()); try { iterator = IteratorUtils.arrayListIterator(intArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(intArray, 2, 3); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.next().equals(Integer.valueOf(2))); assertTrue(iterator.hasPrevious()); assertTrue(!iterator.hasNext()); try { iterator = IteratorUtils.arrayListIterator(intArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(intArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(intArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } }
public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private IteratorUtils(); }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testEmptyIterator() { assertSame(EmptyIterator.INSTANCE, IteratorUtils.EMPTY_ITERATOR); assertSame(EmptyIterator.RESETTABLE_INSTANCE, IteratorUtils.EMPTY_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_ITERATOR instanceof ResettableIterator); assertEquals(false, IteratorUtils.EMPTY_ITERATOR instanceof OrderedIterator); assertEquals(false, IteratorUtils.EMPTY_ITERATOR instanceof ListIterator); assertEquals(false, IteratorUtils.EMPTY_ITERATOR instanceof MapIterator); assertEquals(false, IteratorUtils.EMPTY_ITERATOR.hasNext()); IteratorUtils.EMPTY_ITERATOR.reset(); assertSame(IteratorUtils.EMPTY_ITERATOR, IteratorUtils.EMPTY_ITERATOR); assertSame(IteratorUtils.EMPTY_ITERATOR, IteratorUtils.emptyIterator()); try { IteratorUtils.EMPTY_ITERATOR.next(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_ITERATOR.remove(); fail(); } catch (final IllegalStateException ex) {} }
public static <E> ResettableIterator<E> emptyIterator() { return EmptyIterator.<E>resettableEmptyIterator(); }
IteratorUtils { public static <E> ResettableIterator<E> emptyIterator() { return EmptyIterator.<E>resettableEmptyIterator(); } }
IteratorUtils { public static <E> ResettableIterator<E> emptyIterator() { return EmptyIterator.<E>resettableEmptyIterator(); } private IteratorUtils(); }
IteratorUtils { public static <E> ResettableIterator<E> emptyIterator() { return EmptyIterator.<E>resettableEmptyIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> ResettableIterator<E> emptyIterator() { return EmptyIterator.<E>resettableEmptyIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testStatsCounter() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Integer> rt = TypeToken.of(int.class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "update user set name=? where id=?"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) "ash")); assertThat(args.get(1), equalTo((Object) 100)); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{user}, stat); assertThat(stat.getDatabaseExecuteSuccessCount(), equalTo(1L)); operator.execute(new Object[]{user}, stat); assertThat(stat.getDatabaseExecuteSuccessCount(), equalTo(2L)); operator.setJdbcOperations(new JdbcOperationsAdapter()); try { operator.execute(new Object[]{user}, stat); } catch (UnsupportedOperationException e) { } assertThat(stat.getDatabaseExecuteExceptionCount(), equalTo(1L)); try { operator.execute(new Object[]{user}, stat); } catch (UnsupportedOperationException e) { } assertThat(stat.getDatabaseExecuteExceptionCount(), equalTo(2L)); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void testEmptyListIterator() { assertSame(EmptyListIterator.INSTANCE, IteratorUtils.EMPTY_LIST_ITERATOR); assertSame(EmptyListIterator.RESETTABLE_INSTANCE, IteratorUtils.EMPTY_LIST_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_LIST_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_LIST_ITERATOR instanceof ListIterator); assertEquals(true, IteratorUtils.EMPTY_LIST_ITERATOR instanceof ResettableIterator); assertEquals(true, IteratorUtils.EMPTY_LIST_ITERATOR instanceof ResettableListIterator); assertEquals(false, IteratorUtils.EMPTY_LIST_ITERATOR instanceof MapIterator); assertEquals(false, IteratorUtils.EMPTY_LIST_ITERATOR.hasNext()); assertEquals(0, IteratorUtils.EMPTY_LIST_ITERATOR.nextIndex()); assertEquals(-1, IteratorUtils.EMPTY_LIST_ITERATOR.previousIndex()); IteratorUtils.EMPTY_LIST_ITERATOR.reset(); assertSame(IteratorUtils.EMPTY_LIST_ITERATOR, IteratorUtils.EMPTY_LIST_ITERATOR); assertSame(IteratorUtils.EMPTY_LIST_ITERATOR, IteratorUtils.emptyListIterator()); try { IteratorUtils.EMPTY_LIST_ITERATOR.next(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_LIST_ITERATOR.previous(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_LIST_ITERATOR.remove(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.emptyListIterator().set(null); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.emptyListIterator().add(null); fail(); } catch (final UnsupportedOperationException ex) {} }
public static <E> ResettableListIterator<E> emptyListIterator() { return EmptyListIterator.<E>resettableEmptyListIterator(); }
IteratorUtils { public static <E> ResettableListIterator<E> emptyListIterator() { return EmptyListIterator.<E>resettableEmptyListIterator(); } }
IteratorUtils { public static <E> ResettableListIterator<E> emptyListIterator() { return EmptyListIterator.<E>resettableEmptyListIterator(); } private IteratorUtils(); }
IteratorUtils { public static <E> ResettableListIterator<E> emptyListIterator() { return EmptyListIterator.<E>resettableEmptyListIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> ResettableListIterator<E> emptyListIterator() { return EmptyListIterator.<E>resettableEmptyListIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test @SuppressWarnings("unchecked") public void testEmptyMapIterator() { assertSame(EmptyMapIterator.INSTANCE, IteratorUtils.EMPTY_MAP_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_MAP_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_MAP_ITERATOR instanceof MapIterator); assertEquals(true, IteratorUtils.EMPTY_MAP_ITERATOR instanceof ResettableIterator); assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR instanceof ListIterator); assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR instanceof OrderedIterator); assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR instanceof OrderedMapIterator); assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR.hasNext()); ((ResettableIterator<Object>) IteratorUtils.EMPTY_MAP_ITERATOR).reset(); assertSame(IteratorUtils.EMPTY_MAP_ITERATOR, IteratorUtils.EMPTY_MAP_ITERATOR); assertSame(IteratorUtils.EMPTY_MAP_ITERATOR, IteratorUtils.emptyMapIterator()); try { IteratorUtils.EMPTY_MAP_ITERATOR.next(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_MAP_ITERATOR.remove(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.EMPTY_MAP_ITERATOR.getKey(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.EMPTY_MAP_ITERATOR.getValue(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.EMPTY_MAP_ITERATOR.setValue(null); fail(); } catch (final IllegalStateException ex) {} }
public static <K, V> MapIterator<K, V> emptyMapIterator() { return EmptyMapIterator.<K, V>emptyMapIterator(); }
IteratorUtils { public static <K, V> MapIterator<K, V> emptyMapIterator() { return EmptyMapIterator.<K, V>emptyMapIterator(); } }
IteratorUtils { public static <K, V> MapIterator<K, V> emptyMapIterator() { return EmptyMapIterator.<K, V>emptyMapIterator(); } private IteratorUtils(); }
IteratorUtils { public static <K, V> MapIterator<K, V> emptyMapIterator() { return EmptyMapIterator.<K, V>emptyMapIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <K, V> MapIterator<K, V> emptyMapIterator() { return EmptyMapIterator.<K, V>emptyMapIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test @SuppressWarnings("unchecked") public void testEmptyOrderedIterator() { assertSame(EmptyOrderedIterator.INSTANCE, IteratorUtils.EMPTY_ORDERED_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof OrderedIterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof ResettableIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof ListIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof MapIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR.hasNext()); assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR.hasPrevious()); ((ResettableIterator<Object>) IteratorUtils.EMPTY_ORDERED_ITERATOR).reset(); assertSame(IteratorUtils.EMPTY_ORDERED_ITERATOR, IteratorUtils.EMPTY_ORDERED_ITERATOR); assertSame(IteratorUtils.EMPTY_ORDERED_ITERATOR, IteratorUtils.emptyOrderedIterator()); try { IteratorUtils.EMPTY_ORDERED_ITERATOR.next(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_ORDERED_ITERATOR.previous(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_ORDERED_ITERATOR.remove(); fail(); } catch (final IllegalStateException ex) {} }
public static <E> OrderedIterator<E> emptyOrderedIterator() { return EmptyOrderedIterator.<E>emptyOrderedIterator(); }
IteratorUtils { public static <E> OrderedIterator<E> emptyOrderedIterator() { return EmptyOrderedIterator.<E>emptyOrderedIterator(); } }
IteratorUtils { public static <E> OrderedIterator<E> emptyOrderedIterator() { return EmptyOrderedIterator.<E>emptyOrderedIterator(); } private IteratorUtils(); }
IteratorUtils { public static <E> OrderedIterator<E> emptyOrderedIterator() { return EmptyOrderedIterator.<E>emptyOrderedIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> OrderedIterator<E> emptyOrderedIterator() { return EmptyOrderedIterator.<E>emptyOrderedIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test @SuppressWarnings("unchecked") public void testEmptyOrderedMapIterator() { assertSame(EmptyOrderedMapIterator.INSTANCE, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof MapIterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof OrderedMapIterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof ResettableIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof ListIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.hasNext()); assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.hasPrevious()); ((ResettableIterator<Object>) IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR).reset(); assertSame(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR); assertSame(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR, IteratorUtils.emptyOrderedMapIterator()); try { IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.next(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.previous(); fail(); } catch (final NoSuchElementException ex) {} try { IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.remove(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.getKey(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.getValue(); fail(); } catch (final IllegalStateException ex) {} try { IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.setValue(null); fail(); } catch (final IllegalStateException ex) {} }
public static <K, V> OrderedMapIterator<K, V> emptyOrderedMapIterator() { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); }
IteratorUtils { public static <K, V> OrderedMapIterator<K, V> emptyOrderedMapIterator() { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } }
IteratorUtils { public static <K, V> OrderedMapIterator<K, V> emptyOrderedMapIterator() { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } private IteratorUtils(); }
IteratorUtils { public static <K, V> OrderedMapIterator<K, V> emptyOrderedMapIterator() { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <K, V> OrderedMapIterator<K, V> emptyOrderedMapIterator() { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testNodeListIterator() { final Node[] nodes = createNodes(); final NodeList nodeList = createNodeList(nodes); final Iterator<Node> iterator = IteratorUtils.nodeListIterator(nodeList); int expectedNodeIndex = 0; for (final Node actual : IteratorUtils.asIterable(iterator)) { assertEquals(nodes[expectedNodeIndex], actual); ++expectedNodeIndex; } assertTrue(expectedNodeIndex > 0); assertFalse("should not be able to iterate twice", IteratorUtils.asIterable(iterator).iterator().hasNext()); }
public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); }
IteratorUtils { public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); } }
IteratorUtils { public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); } private IteratorUtils(); }
IteratorUtils { public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testCollatedIterator() { try { IteratorUtils.collatedIterator(null, collectionOdd.iterator(), null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } try { IteratorUtils.collatedIterator(null, null, collectionEven.iterator()); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } Iterator<Integer> it = IteratorUtils.collatedIterator(null, collectionOdd.iterator(), collectionEven.iterator()); List<Integer> result = IteratorUtils.toList(it); assertEquals(12, result.size()); List<Integer> combinedList = new ArrayList<Integer>(); combinedList.addAll(collectionOdd); combinedList.addAll(collectionEven); Collections.sort(combinedList); assertEquals(combinedList, result); it = IteratorUtils.collatedIterator(null, collectionOdd.iterator(), emptyCollection.iterator()); result = IteratorUtils.toList(it); assertEquals(collectionOdd, result); final Comparator<Integer> reverseComparator = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); Collections.reverse(collectionOdd); Collections.reverse(collectionEven); Collections.reverse(combinedList); it = IteratorUtils.collatedIterator(reverseComparator, collectionOdd.iterator(), collectionEven.iterator()); result = IteratorUtils.toList(it); assertEquals(combinedList, result); }
public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { @SuppressWarnings("unchecked") final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator; return new CollatingIterator<E>(comp, iterator1, iterator2); }
IteratorUtils { public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { @SuppressWarnings("unchecked") final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator; return new CollatingIterator<E>(comp, iterator1, iterator2); } }
IteratorUtils { public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { @SuppressWarnings("unchecked") final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator; return new CollatingIterator<E>(comp, iterator1, iterator2); } private IteratorUtils(); }
IteratorUtils { public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { @SuppressWarnings("unchecked") final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator; return new CollatingIterator<E>(comp, iterator1, iterator2); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { @SuppressWarnings("unchecked") final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator; return new CollatingIterator<E>(comp, iterator1, iterator2); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void forEach() { final List<Integer> listA = new ArrayList<Integer>(); listA.add(1); final List<Integer> listB = new ArrayList<Integer>(); listB.add(2); final Closure<List<Integer>> testClosure = ClosureUtils.invokerClosure("clear"); final Collection<List<Integer>> col = new ArrayList<List<Integer>>(); col.add(listA); col.add(listB); IteratorUtils.forEach(col.iterator(), testClosure); assertTrue(listA.isEmpty() && listB.isEmpty()); try { IteratorUtils.forEach(col.iterator(), null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } IteratorUtils.forEach(null, testClosure); col.add(null); IteratorUtils.forEach(col.iterator(), testClosure); }
public static <E> void forEach(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); closure.execute(element); } } }
IteratorUtils { public static <E> void forEach(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); closure.execute(element); } } } }
IteratorUtils { public static <E> void forEach(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); closure.execute(element); } } } private IteratorUtils(); }
IteratorUtils { public static <E> void forEach(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); closure.execute(element); } } } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> void forEach(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); closure.execute(element); } } } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void forEachButLast() { final List<Integer> listA = new ArrayList<Integer>(); listA.add(1); final List<Integer> listB = new ArrayList<Integer>(); listB.add(2); final Closure<List<Integer>> testClosure = ClosureUtils.invokerClosure("clear"); final Collection<List<Integer>> col = new ArrayList<List<Integer>>(); col.add(listA); col.add(listB); List<Integer> last = IteratorUtils.forEachButLast(col.iterator(), testClosure); assertTrue(listA.isEmpty() && !listB.isEmpty()); assertSame(listB, last); try { IteratorUtils.forEachButLast(col.iterator(), null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } IteratorUtils.forEachButLast(null, testClosure); col.add(null); col.add(null); last = IteratorUtils.forEachButLast(col.iterator(), testClosure); assertNull(last); }
public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null."); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (iterator.hasNext()) { closure.execute(element); } else { return element; } } } return null; }
IteratorUtils { public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null."); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (iterator.hasNext()) { closure.execute(element); } else { return element; } } } return null; } }
IteratorUtils { public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null."); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (iterator.hasNext()) { closure.execute(element); } else { return element; } } } return null; } private IteratorUtils(); }
IteratorUtils { public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null."); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (iterator.hasNext()) { closure.execute(element); } else { return element; } } } return null; } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null."); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (iterator.hasNext()) { closure.execute(element); } else { return element; } } } return null; } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void find() { Predicate<Number> testPredicate = equalPredicate((Number) 4); Integer test = IteratorUtils.find(iterableA.iterator(), testPredicate); assertTrue(test.equals(4)); testPredicate = equalPredicate((Number) 45); test = IteratorUtils.find(iterableA.iterator(), testPredicate); assertTrue(test == null); assertNull(IteratorUtils.find(null,testPredicate)); try { assertNull(IteratorUtils.find(iterableA.iterator(), null)); fail("expecting NullPointerException"); } catch (final NullPointerException npe) { } }
public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (predicate.evaluate(element)) { return element; } } } return null; }
IteratorUtils { public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (predicate.evaluate(element)) { return element; } } } return null; } }
IteratorUtils { public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (predicate.evaluate(element)) { return element; } } } return null; } private IteratorUtils(); }
IteratorUtils { public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (predicate.evaluate(element)) { return element; } } } return null; } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (predicate.evaluate(element)) { return element; } } } return null; } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void indexOf() { Predicate<Number> testPredicate = equalPredicate((Number) 4); int index = IteratorUtils.indexOf(iterableA.iterator(), testPredicate); assertEquals(6, index); testPredicate = equalPredicate((Number) 45); index = IteratorUtils.indexOf(iterableA.iterator(), testPredicate); assertEquals(-1, index); assertEquals(-1, IteratorUtils.indexOf(null, testPredicate)); try { assertNull(IteratorUtils.indexOf(iterableA.iterator(), null)); fail("expecting NullPointerException"); } catch (final NullPointerException npe) { } }
public static <E> int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { for(int index = 0; iterator.hasNext(); index++) { final E element = iterator.next(); if (predicate.evaluate(element)) { return index; } } } return -1; }
IteratorUtils { public static <E> int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { for(int index = 0; iterator.hasNext(); index++) { final E element = iterator.next(); if (predicate.evaluate(element)) { return index; } } } return -1; } }
IteratorUtils { public static <E> int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { for(int index = 0; iterator.hasNext(); index++) { final E element = iterator.next(); if (predicate.evaluate(element)) { return index; } } } return -1; } private IteratorUtils(); }
IteratorUtils { public static <E> int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { for(int index = 0; iterator.hasNext(); index++) { final E element = iterator.next(); if (predicate.evaluate(element)) { return index; } } } return -1; } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { for(int index = 0; iterator.hasNext(); index++) { final E element = iterator.next(); if (predicate.evaluate(element)) { return index; } } } return -1; } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void testUpdateReturnTypeError() throws Exception { thrown.expect(DescriptionException.class); thrown.expectMessage("the return type of update expected one of [void, int, long, boolean, " + "Void, Integer, Long, Boolean] but class java.lang.String"); TypeToken<User> pt = TypeToken.of(User.class); TypeToken<String> rt = TypeToken.of(String.class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "update user set name=? where id=?"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) "ash")); assertThat(args.get(1), equalTo((Object) 100)); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); operator.execute(new Object[]{user}, InvocationStat.create()); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void getFromIterator() throws Exception { Iterator<Integer> iterator = iterableA.iterator(); assertEquals(1, (int) IteratorUtils.get(iterator, 0)); iterator = iterableA.iterator(); assertEquals(2, (int) IteratorUtils.get(iterator, 1)); try { IteratorUtils.get(iterator, 10); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException e) { } assertTrue(!iterator.hasNext()); }
public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); }
IteratorUtils { public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); } }
IteratorUtils { public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); } private IteratorUtils(); }
IteratorUtils { public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); }
IteratorUtils { public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator, final Transformer<? super E, String> transformer, final String delimiter, final String prefix, final String suffix); @SuppressWarnings("rawtypes") static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes") static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes") static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes") static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }
@Test public void getCardinalityMap() { final Map<Number, Integer> freqA = CollectionUtils.<Number>getCardinalityMap(iterableA); assertEquals(1, (int) freqA.get(1)); assertEquals(2, (int) freqA.get(2)); assertEquals(3, (int) freqA.get(3)); assertEquals(4, (int) freqA.get(4)); assertNull(freqA.get(5)); final Map<Long, Integer> freqB = CollectionUtils.getCardinalityMap(iterableB); assertNull(freqB.get(1L)); assertEquals(4, (int) freqB.get(2L)); assertEquals(3, (int) freqB.get(3L)); assertEquals(2, (int) freqB.get(4L)); assertEquals(1, (int) freqB.get(5L)); }
public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) { final Map<O, Integer> count = new HashMap<O, Integer>(); for (final O obj : coll) { final Integer c = count.get(obj); if (c == null) { count.put(obj, Integer.valueOf(1)); } else { count.put(obj, Integer.valueOf(c.intValue() + 1)); } } return count; }
CollectionUtils { public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) { final Map<O, Integer> count = new HashMap<O, Integer>(); for (final O obj : coll) { final Integer c = count.get(obj); if (c == null) { count.put(obj, Integer.valueOf(1)); } else { count.put(obj, Integer.valueOf(c.intValue() + 1)); } } return count; } }
CollectionUtils { public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) { final Map<O, Integer> count = new HashMap<O, Integer>(); for (final O obj : coll) { final Integer c = count.get(obj); if (c == null) { count.put(obj, Integer.valueOf(1)); } else { count.put(obj, Integer.valueOf(c.intValue() + 1)); } } return count; } private CollectionUtils(); }
CollectionUtils { public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) { final Map<O, Integer> count = new HashMap<O, Integer>(); for (final O obj : coll) { final Integer c = count.get(obj); if (c == null) { count.put(obj, Integer.valueOf(1)); } else { count.put(obj, Integer.valueOf(c.intValue() + 1)); } } return count; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) { final Map<O, Integer> count = new HashMap<O, Integer>(); for (final O obj : coll) { final Integer c = count.get(obj); if (c == null) { count.put(obj, Integer.valueOf(1)); } else { count.put(obj, Integer.valueOf(c.intValue() + 1)); } } return count; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test @Deprecated public void cardinality() { assertEquals(1, CollectionUtils.cardinality(1, iterableA)); assertEquals(2, CollectionUtils.cardinality(2, iterableA)); assertEquals(3, CollectionUtils.cardinality(3, iterableA)); assertEquals(4, CollectionUtils.cardinality(4, iterableA)); assertEquals(0, CollectionUtils.cardinality(5, iterableA)); assertEquals(0, CollectionUtils.cardinality(1L, iterableB)); assertEquals(4, CollectionUtils.cardinality(2L, iterableB)); assertEquals(3, CollectionUtils.cardinality(3L, iterableB)); assertEquals(2, CollectionUtils.cardinality(4L, iterableB)); assertEquals(1, CollectionUtils.cardinality(5L, iterableB)); assertEquals(0, CollectionUtils.cardinality(2L, iterableA2)); assertEquals(0, CollectionUtils.cardinality(2, iterableB2)); final Set<String> set = new HashSet<String>(); set.add("A"); set.add("C"); set.add("E"); set.add("E"); assertEquals(1, CollectionUtils.cardinality("A", set)); assertEquals(0, CollectionUtils.cardinality("B", set)); assertEquals(1, CollectionUtils.cardinality("C", set)); assertEquals(0, CollectionUtils.cardinality("D", set)); assertEquals(1, CollectionUtils.cardinality("E", set)); final Bag<String> bag = new HashBag<String>(); bag.add("A", 3); bag.add("C"); bag.add("E"); bag.add("E"); assertEquals(3, CollectionUtils.cardinality("A", bag)); assertEquals(0, CollectionUtils.cardinality("B", bag)); assertEquals(1, CollectionUtils.cardinality("C", bag)); assertEquals(0, CollectionUtils.cardinality("D", bag)); assertEquals(2, CollectionUtils.cardinality("E", bag)); }
@Deprecated public static <O> int cardinality(final O obj, final Iterable<? super O> coll) { if (coll == null) { throw new NullPointerException("coll must not be null."); } return IterableUtils.frequency(coll, obj); }
CollectionUtils { @Deprecated public static <O> int cardinality(final O obj, final Iterable<? super O> coll) { if (coll == null) { throw new NullPointerException("coll must not be null."); } return IterableUtils.frequency(coll, obj); } }
CollectionUtils { @Deprecated public static <O> int cardinality(final O obj, final Iterable<? super O> coll) { if (coll == null) { throw new NullPointerException("coll must not be null."); } return IterableUtils.frequency(coll, obj); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <O> int cardinality(final O obj, final Iterable<? super O> coll) { if (coll == null) { throw new NullPointerException("coll must not be null."); } return IterableUtils.frequency(coll, obj); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <O> int cardinality(final O obj, final Iterable<? super O> coll) { if (coll == null) { throw new NullPointerException("coll must not be null."); } return IterableUtils.frequency(coll, obj); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void containsAll() { final Collection<String> empty = new ArrayList<String>(0); final Collection<String> one = new ArrayList<String>(1); one.add("1"); final Collection<String> two = new ArrayList<String>(1); two.add("2"); final Collection<String> three = new ArrayList<String>(1); three.add("3"); final Collection<String> odds = new ArrayList<String>(2); odds.add("1"); odds.add("3"); final Collection<String> multiples = new ArrayList<String>(3); multiples.add("1"); multiples.add("3"); multiples.add("1"); assertTrue("containsAll({1},{1,3}) should return false.", !CollectionUtils.containsAll(one, odds)); assertTrue("containsAll({1,3},{1}) should return true.", CollectionUtils.containsAll(odds, one)); assertTrue("containsAll({3},{1,3}) should return false.", !CollectionUtils.containsAll(three, odds)); assertTrue("containsAll({1,3},{3}) should return true.", CollectionUtils.containsAll(odds, three)); assertTrue("containsAll({2},{2}) should return true.", CollectionUtils.containsAll(two, two)); assertTrue("containsAll({1,3},{1,3}) should return true.", CollectionUtils.containsAll(odds, odds)); assertTrue("containsAll({2},{1,3}) should return false.", !CollectionUtils.containsAll(two, odds)); assertTrue("containsAll({1,3},{2}) should return false.", !CollectionUtils.containsAll(odds, two)); assertTrue("containsAll({1},{3}) should return false.", !CollectionUtils.containsAll(one, three)); assertTrue("containsAll({3},{1}) should return false.", !CollectionUtils.containsAll(three, one)); assertTrue("containsAll({1,3},{}) should return true.", CollectionUtils.containsAll(odds, empty)); assertTrue("containsAll({},{1,3}) should return false.", !CollectionUtils.containsAll(empty, odds)); assertTrue("containsAll({},{}) should return true.", CollectionUtils.containsAll(empty, empty)); assertTrue("containsAll({1,3},{1,3,1}) should return true.", CollectionUtils.containsAll(odds, multiples)); assertTrue("containsAll({1,3,1},{1,3,1}) should return true.", CollectionUtils.containsAll(odds, odds)); }
public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySeen.contains(nextElement)) { continue; } boolean foundCurrentElement = false; while (it.hasNext()) { final Object p = it.next(); elementsAlreadySeen.add(p); if (nextElement == null ? p == null : nextElement.equals(p)) { foundCurrentElement = true; break; } } if (foundCurrentElement) { continue; } else { return false; } } return true; } }
CollectionUtils { public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySeen.contains(nextElement)) { continue; } boolean foundCurrentElement = false; while (it.hasNext()) { final Object p = it.next(); elementsAlreadySeen.add(p); if (nextElement == null ? p == null : nextElement.equals(p)) { foundCurrentElement = true; break; } } if (foundCurrentElement) { continue; } else { return false; } } return true; } } }
CollectionUtils { public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySeen.contains(nextElement)) { continue; } boolean foundCurrentElement = false; while (it.hasNext()) { final Object p = it.next(); elementsAlreadySeen.add(p); if (nextElement == null ? p == null : nextElement.equals(p)) { foundCurrentElement = true; break; } } if (foundCurrentElement) { continue; } else { return false; } } return true; } } private CollectionUtils(); }
CollectionUtils { public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySeen.contains(nextElement)) { continue; } boolean foundCurrentElement = false; while (it.hasNext()) { final Object p = it.next(); elementsAlreadySeen.add(p); if (nextElement == null ? p == null : nextElement.equals(p)) { foundCurrentElement = true; break; } } if (foundCurrentElement) { continue; } else { return false; } } return true; } } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySeen.contains(nextElement)) { continue; } boolean foundCurrentElement = false; while (it.hasNext()) { final Object p = it.next(); elementsAlreadySeen.add(p); if (nextElement == null ? p == null : nextElement.equals(p)) { foundCurrentElement = true; break; } } if (foundCurrentElement) { continue; } else { return false; } } return true; } } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void containsAny() { final Collection<String> empty = new ArrayList<String>(0); final Collection<String> one = new ArrayList<String>(1); one.add("1"); final Collection<String> two = new ArrayList<String>(1); two.add("2"); final Collection<String> three = new ArrayList<String>(1); three.add("3"); final Collection<String> odds = new ArrayList<String>(2); odds.add("1"); odds.add("3"); assertTrue("containsAny({1},{1,3}) should return true.", CollectionUtils.containsAny(one, odds)); assertTrue("containsAny({1,3},{1}) should return true.", CollectionUtils.containsAny(odds, one)); assertTrue("containsAny({3},{1,3}) should return true.", CollectionUtils.containsAny(three, odds)); assertTrue("containsAny({1,3},{3}) should return true.", CollectionUtils.containsAny(odds, three)); assertTrue("containsAny({2},{2}) should return true.", CollectionUtils.containsAny(two, two)); assertTrue("containsAny({1,3},{1,3}) should return true.", CollectionUtils.containsAny(odds, odds)); assertTrue("containsAny({2},{1,3}) should return false.", !CollectionUtils.containsAny(two, odds)); assertTrue("containsAny({1,3},{2}) should return false.", !CollectionUtils.containsAny(odds, two)); assertTrue("containsAny({1},{3}) should return false.", !CollectionUtils.containsAny(one, three)); assertTrue("containsAny({3},{1}) should return false.", !CollectionUtils.containsAny(three, one)); assertTrue("containsAny({1,3},{}) should return false.", !CollectionUtils.containsAny(odds, empty)); assertTrue("containsAny({},{1,3}) should return false.", !CollectionUtils.containsAny(empty, odds)); assertTrue("containsAny({},{}) should return false.", !CollectionUtils.containsAny(empty, empty)); }
public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) { if (coll1.size() < coll2.size()) { for (final Object aColl1 : coll1) { if (coll2.contains(aColl1)) { return true; } } } else { for (final Object aColl2 : coll2) { if (coll1.contains(aColl2)) { return true; } } } return false; }
CollectionUtils { public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) { if (coll1.size() < coll2.size()) { for (final Object aColl1 : coll1) { if (coll2.contains(aColl1)) { return true; } } } else { for (final Object aColl2 : coll2) { if (coll1.contains(aColl2)) { return true; } } } return false; } }
CollectionUtils { public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) { if (coll1.size() < coll2.size()) { for (final Object aColl1 : coll1) { if (coll2.contains(aColl1)) { return true; } } } else { for (final Object aColl2 : coll2) { if (coll1.contains(aColl2)) { return true; } } } return false; } private CollectionUtils(); }
CollectionUtils { public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) { if (coll1.size() < coll2.size()) { for (final Object aColl1 : coll1) { if (coll2.contains(aColl1)) { return true; } } } else { for (final Object aColl2 : coll2) { if (coll1.contains(aColl2)) { return true; } } } return false; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) { if (coll1.size() < coll2.size()) { for (final Object aColl1 : coll1) { if (coll2.contains(aColl1)) { return true; } } } else { for (final Object aColl2 : coll2) { if (coll1.contains(aColl2)) { return true; } } } return false; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void union() { final Collection<Integer> col = CollectionUtils.union(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertEquals(Integer.valueOf(1), freq.get(1)); assertEquals(Integer.valueOf(4), freq.get(2)); assertEquals(Integer.valueOf(3), freq.get(3)); assertEquals(Integer.valueOf(4), freq.get(4)); assertEquals(Integer.valueOf(1), freq.get(5)); final Collection<Number> col2 = CollectionUtils.union(collectionC2, iterableA); final Map<Number, Integer> freq2 = CollectionUtils.getCardinalityMap(col2); assertEquals(Integer.valueOf(1), freq2.get(1)); assertEquals(Integer.valueOf(4), freq2.get(2)); assertEquals(Integer.valueOf(3), freq2.get(3)); assertEquals(Integer.valueOf(4), freq2.get(4)); assertEquals(Integer.valueOf(1), freq2.get(5)); }
public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj)); } return helper.list(); }
CollectionUtils { public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj)); } return helper.list(); } }
CollectionUtils { public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj)); } return helper.list(); } private CollectionUtils(); }
CollectionUtils { public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj)); } return helper.list(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj)); } return helper.list(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void intersection() { final Collection<Integer> col = CollectionUtils.intersection(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertNull(freq.get(1)); assertEquals(Integer.valueOf(2), freq.get(2)); assertEquals(Integer.valueOf(3), freq.get(3)); assertEquals(Integer.valueOf(2), freq.get(4)); assertNull(freq.get(5)); final Collection<Number> col2 = CollectionUtils.intersection(collectionC2, collectionA); final Map<Number, Integer> freq2 = CollectionUtils.getCardinalityMap(col2); assertNull(freq2.get(1)); assertEquals(Integer.valueOf(2), freq2.get(2)); assertEquals(Integer.valueOf(3), freq2.get(3)); assertEquals(Integer.valueOf(2), freq2.get(4)); assertNull(freq2.get(5)); }
public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.min(obj)); } return helper.list(); }
CollectionUtils { public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.min(obj)); } return helper.list(); } }
CollectionUtils { public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.min(obj)); } return helper.list(); } private CollectionUtils(); }
CollectionUtils { public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.min(obj)); } return helper.list(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.min(obj)); } return helper.list(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void disjunction() { final Collection<Integer> col = CollectionUtils.disjunction(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertEquals(Integer.valueOf(1), freq.get(1)); assertEquals(Integer.valueOf(2), freq.get(2)); assertNull(freq.get(3)); assertEquals(Integer.valueOf(2), freq.get(4)); assertEquals(Integer.valueOf(1), freq.get(5)); final Collection<Number> col2 = CollectionUtils.disjunction(collectionC2, collectionA); final Map<Number, Integer> freq2 = CollectionUtils.getCardinalityMap(col2); assertEquals(Integer.valueOf(1), freq2.get(1)); assertEquals(Integer.valueOf(2), freq2.get(2)); assertNull(freq2.get(3)); assertEquals(Integer.valueOf(2), freq2.get(4)); assertEquals(Integer.valueOf(1), freq2.get(5)); }
public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj) - helper.min(obj)); } return helper.list(); }
CollectionUtils { public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj) - helper.min(obj)); } return helper.list(); } }
CollectionUtils { public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj) - helper.min(obj)); } return helper.list(); } private CollectionUtils(); }
CollectionUtils { public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj) - helper.min(obj)); } return helper.list(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj) - helper.min(obj)); } return helper.list(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testSubtract() { final Collection<Integer> col = CollectionUtils.subtract(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertEquals(Integer.valueOf(1), freq.get(1)); assertNull(freq.get(2)); assertNull(freq.get(3)); assertEquals(Integer.valueOf(2), freq.get(4)); assertNull(freq.get(5)); final Collection<Number> col2 = CollectionUtils.subtract(collectionC2, collectionA); final Map<Number, Integer> freq2 = CollectionUtils.getCardinalityMap(col2); assertEquals(Integer.valueOf(1), freq2.get(5)); assertNull(freq2.get(4)); assertNull(freq2.get(3)); assertEquals(Integer.valueOf(2), freq2.get(2)); assertNull(freq2.get(1)); }
public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) { final Predicate<O> p = TruePredicate.truePredicate(); return subtract(a, b, p); }
CollectionUtils { public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) { final Predicate<O> p = TruePredicate.truePredicate(); return subtract(a, b, p); } }
CollectionUtils { public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) { final Predicate<O> p = TruePredicate.truePredicate(); return subtract(a, b, p); } private CollectionUtils(); }
CollectionUtils { public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) { final Predicate<O> p = TruePredicate.truePredicate(); return subtract(a, b, p); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) { final Predicate<O> p = TruePredicate.truePredicate(); return subtract(a, b, p); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsSubCollectionOfSelf() { assertTrue(CollectionUtils.isSubCollection(collectionA, collectionA)); assertTrue(CollectionUtils.isSubCollection(collectionB, collectionB)); }
public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testUpdateReturnGeneratedIdReturnTypeError() throws Exception { thrown.expect(DescriptionException.class); thrown.expectMessage("the return type of update(returnGeneratedId) expected " + "one of [int, long, Integer, Long] but void"); TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Void> rt = TypeToken.of(void.class); String srcSql = "insert into user(id, name) values(:1.id, :1.name)"; AbstractOperator operator = getOperatorReturnGeneratedId(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql, GeneratedKeyHolder holder) { String sql = boundSql.getSql(); List<Object> args = boundSql.getArgs(); String descSql = "insert into user(id, name) values(?, ?)"; assertThat(sql, equalTo(descSql)); assertThat(args.size(), equalTo(2)); assertThat(args.get(0), equalTo((Object) 100)); assertThat(args.get(1), equalTo((Object) "ash")); assertThat(holder.getTypeHandler().getClass().equals(IntegerTypeHandler.class), is(true)); holder.setKey(100); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); operator.execute(new Object[]{user}, InvocationStat.create()); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
UpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } UpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); Object execute(InvocationContext context, InvocationStat stat); }
@Test public void testIsSubCollection() { assertTrue(!CollectionUtils.isSubCollection(collectionA, collectionC)); assertTrue(!CollectionUtils.isSubCollection(collectionC, collectionA)); }
public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsSubCollection2() { final Collection<Integer> c = new ArrayList<Integer>(); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(1); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(2); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(2); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(3); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(3); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(3); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(4); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(4); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(4); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(!CollectionUtils.isSubCollection(collectionA, c)); c.add(4); assertTrue(CollectionUtils.isSubCollection(c, collectionA)); assertTrue(CollectionUtils.isSubCollection(collectionA, c)); c.add(5); assertTrue(!CollectionUtils.isSubCollection(c, collectionA)); assertTrue(CollectionUtils.isSubCollection(collectionA, c)); }
public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsEqualCollectionToSelf() { assertTrue(CollectionUtils.isEqualCollection(collectionA, collectionA)); assertTrue(CollectionUtils.isEqualCollection(collectionB, collectionB)); }
public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsEqualCollection() { assertTrue(!CollectionUtils.isEqualCollection(collectionA, collectionC)); assertTrue(!CollectionUtils.isEqualCollection(collectionC, collectionA)); }
public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsEqualCollectionReturnsFalse() { final List<Integer> b = new ArrayList<Integer>(collectionA); b.remove(1); b.add(5); assertFalse(CollectionUtils.isEqualCollection(collectionA, b)); assertFalse(CollectionUtils.isEqualCollection(b, collectionA)); }
public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsEqualCollection2() { final Collection<String> a = new ArrayList<String>(); final Collection<String> b = new ArrayList<String>(); assertTrue(CollectionUtils.isEqualCollection(a, b)); assertTrue(CollectionUtils.isEqualCollection(b, a)); a.add("1"); assertTrue(!CollectionUtils.isEqualCollection(a, b)); assertTrue(!CollectionUtils.isEqualCollection(b, a)); b.add("1"); assertTrue(CollectionUtils.isEqualCollection(a, b)); assertTrue(CollectionUtils.isEqualCollection(b, a)); a.add("2"); assertTrue(!CollectionUtils.isEqualCollection(a, b)); assertTrue(!CollectionUtils.isEqualCollection(b, a)); b.add("2"); assertTrue(CollectionUtils.isEqualCollection(a, b)); assertTrue(CollectionUtils.isEqualCollection(b, a)); a.add("1"); assertTrue(!CollectionUtils.isEqualCollection(a, b)); assertTrue(!CollectionUtils.isEqualCollection(b, a)); b.add("1"); assertTrue(CollectionUtils.isEqualCollection(a, b)); assertTrue(CollectionUtils.isEqualCollection(b, a)); }
public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected=NullPointerException.class) public void testIsEqualCollectionNullEquator() { CollectionUtils.isEqualCollection(collectionA, collectionA, null); }
public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Object obj : helper.cardinalityA.keySet()) { if(helper.freqA(obj) != helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testIsProperSubCollection() { final Collection<String> a = new ArrayList<String>(); final Collection<String> b = new ArrayList<String>(); assertTrue(!CollectionUtils.isProperSubCollection(a, b)); b.add("1"); assertTrue(CollectionUtils.isProperSubCollection(a, b)); assertTrue(!CollectionUtils.isProperSubCollection(b, a)); assertTrue(!CollectionUtils.isProperSubCollection(b, b)); assertTrue(!CollectionUtils.isProperSubCollection(a, a)); a.add("1"); a.add("2"); b.add("2"); assertTrue(!CollectionUtils.isProperSubCollection(b, a)); assertTrue(!CollectionUtils.isProperSubCollection(a, b)); a.add("1"); assertTrue(CollectionUtils.isProperSubCollection(b, a)); assertTrue(CollectionUtils.isProperSubCollection(CollectionUtils.intersection(collectionA, collectionC), collectionA)); assertTrue(CollectionUtils.isProperSubCollection(CollectionUtils.subtract(a, b), a)); assertTrue(!CollectionUtils.isProperSubCollection(a, CollectionUtils.subtract(a, b))); }
public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) { return a.size() < b.size() && CollectionUtils.isSubCollection(a, b); }
CollectionUtils { public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) { return a.size() < b.size() && CollectionUtils.isSubCollection(a, b); } }
CollectionUtils { public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) { return a.size() < b.size() && CollectionUtils.isSubCollection(a, b); } private CollectionUtils(); }
CollectionUtils { public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) { return a.size() < b.size() && CollectionUtils.isSubCollection(a, b); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) { return a.size() < b.size() && CollectionUtils.isSubCollection(a, b); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test @Deprecated public void find() { Predicate<Number> testPredicate = equalPredicate((Number) 4); Integer test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test.equals(4)); testPredicate = equalPredicate((Number) 45); test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test == null); assertNull(CollectionUtils.find(null,testPredicate)); assertNull(CollectionUtils.find(collectionA, null)); }
@Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; }
CollectionUtils { @Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; } }
CollectionUtils { @Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected = FunctorException.class) @Deprecated public void forAllDoFailure() { final Closure<String> testClosure = ClosureUtils.invokerClosure("clear"); final Collection<String> col = new ArrayList<String>(); col.add("x"); CollectionUtils.forAllDo(col, testClosure); }
@Deprecated public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) { if (closure != null) { IterableUtils.forEach(collection, closure); } return closure; }
CollectionUtils { @Deprecated public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) { if (closure != null) { IterableUtils.forEach(collection, closure); } return closure; } }
CollectionUtils { @Deprecated public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) { if (closure != null) { IterableUtils.forEach(collection, closure); } return closure; } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) { if (closure != null) { IterableUtils.forEach(collection, closure); } return closure; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) { if (closure != null) { IterableUtils.forEach(collection, closure); } return closure; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testQueryObject() throws Exception { TypeToken<User> t = TypeToken.of(User.class); String srcSql = "select * from user where id=:1.id and name=:1.name"; AbstractOperator operator = getOperator(t, t, srcSql, new ArrayList<Annotation>()); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> T queryForObject(DataSource ds, BoundSql boundSql, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id=? and name=?"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(2)); assertThat(args[0], equalTo((Object) 100)); assertThat(args[1], equalTo((Object) "ash")); assertThat(rowMapper.getMappedClass().equals(User.class), is(true)); return null; } }); User user = new User(); user.setId(100); user.setName("ash"); operator.execute(new Object[]{user}, InvocationStat.create()); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
@Test public void getFromMap() { final Map<String, String> expected = new HashMap<String, String>(); expected.put("zeroKey", "zero"); expected.put("oneKey", "one"); final Map<String, String> found = new HashMap<String, String>(); Map.Entry<String, String> entry = CollectionUtils.get(expected, 0); found.put(entry.getKey(), entry.getValue()); entry = CollectionUtils.get(expected, 1); found.put(entry.getKey(), entry.getValue()); assertEquals(expected, found); try { CollectionUtils.get(expected, 2); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException e) { } try { CollectionUtils.get(expected, -2); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException e) { } final SortedMap<String, String> map = new TreeMap<String, String>(); map.put("zeroKey", "zero"); map.put("oneKey", "one"); Map.Entry<String, String> test = CollectionUtils.get(map, 1); assertEquals("zeroKey", test.getKey()); assertEquals("zero", test.getValue()); test = CollectionUtils.get(map, 0); assertEquals("oneKey", test.getKey()); assertEquals("one", test.getValue()); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected=IndexOutOfBoundsException.class) public void getFromList() throws Exception { final List<String> list = createMock(List.class); expect(list.get(0)).andReturn("zero"); expect(list.get(1)).andReturn("one"); replay(); final String string = CollectionUtils.get(list, 0); assertEquals("zero", string); assertEquals("one", CollectionUtils.get(list, 1)); CollectionUtils.get(new ArrayList<Object>(), 2); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test @Deprecated public void getFromIterator() throws Exception { Iterator<Integer> iterator = iterableA.iterator(); assertEquals(1, (int) CollectionUtils.get(iterator, 0)); iterator = iterableA.iterator(); assertEquals(2, (int) CollectionUtils.get(iterator, 1)); try { CollectionUtils.get(iterator, 10); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException e) { } assertTrue(!iterator.hasNext()); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test @Deprecated public void getFromEnumeration() throws Exception { final Vector<String> vector = new Vector<String>(); vector.addElement("zero"); vector.addElement("one"); Enumeration<String> en = vector.elements(); assertEquals("zero", CollectionUtils.get(en, 0)); en = vector.elements(); assertEquals("one", CollectionUtils.get(en, 1)); try { CollectionUtils.get(en, 3); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException e) { } assertTrue(!en.hasMoreElements()); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected = IndexOutOfBoundsException.class) @Deprecated public void getFromIterable() throws Exception { final Bag<String> bag = new HashBag<String>(); bag.add("element", 1); assertEquals("element", CollectionUtils.get(bag, 0)); CollectionUtils.get(bag, 1); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected = IndexOutOfBoundsException.class) public void getFromObjectArray() throws Exception { final Object[] objArray = new Object[2]; objArray[0] = "zero"; objArray[1] = "one"; assertEquals("zero", CollectionUtils.get(objArray, 0)); assertEquals("one", CollectionUtils.get(objArray, 1)); CollectionUtils.get(objArray, 2); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected = IndexOutOfBoundsException.class) public void getFromPrimitiveArray() throws Exception { final int[] array = new int[2]; array[0] = 10; array[1] = 20; assertEquals(10, CollectionUtils.get(array, 0)); assertEquals(20, CollectionUtils.get(array, 1)); CollectionUtils.get(array, 2); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected=IllegalArgumentException.class) public void getFromObject() throws Exception { final Object obj = new Object(); CollectionUtils.get(obj, 0); }
@Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testSize_List() { List<String> list = null; assertEquals(0, CollectionUtils.size(list)); list = new ArrayList<String>(); assertEquals(0, CollectionUtils.size(list)); list.add("a"); assertEquals(1, CollectionUtils.size(list)); list.add("b"); assertEquals(2, CollectionUtils.size(list)); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testSize_Map() { final Map<String, String> map = new HashMap<String, String>(); assertEquals(0, CollectionUtils.size(map)); map.put("1", "a"); assertEquals(1, CollectionUtils.size(map)); map.put("2", "b"); assertEquals(2, CollectionUtils.size(map)); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testQueryList() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<List<User>> rt = new TypeToken<List<User>>() { }; String srcSql = "select * from user where id=:1.id and name=:1.name"; AbstractOperator operator = getOperator(pt, rt, srcSql, new ArrayList<Annotation>()); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> List<T> queryForList(DataSource ds, BoundSql boundSql, ListSupplier listSupplier, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id=? and name=?"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(2)); assertThat(args[0], equalTo((Object) 100)); assertThat(args[1], equalTo((Object) "ash")); assertThat(rowMapper.getMappedClass().equals(User.class), is(true)); return null; } }); User user = new User(); user.setId(100); user.setName("ash"); operator.execute(new Object[]{user}, InvocationStat.create()); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
@Test public void testSize_Array() { final Object[] objectArray = new Object[0]; assertEquals(0, CollectionUtils.size(objectArray)); final String[] stringArray = new String[3]; assertEquals(3, CollectionUtils.size(stringArray)); stringArray[0] = "a"; stringArray[1] = "b"; stringArray[2] = "c"; assertEquals(3, CollectionUtils.size(stringArray)); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testSize_PrimitiveArray() { final int[] intArray = new int[0]; assertEquals(0, CollectionUtils.size(intArray)); final double[] doubleArray = new double[3]; assertEquals(3, CollectionUtils.size(doubleArray)); doubleArray[0] = 0.0d; doubleArray[1] = 1.0d; doubleArray[2] = 2.5d; assertEquals(3, CollectionUtils.size(doubleArray)); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testSize_Enumeration() { final Vector<String> list = new Vector<String>(); assertEquals(0, CollectionUtils.size(list.elements())); list.add("a"); assertEquals(1, CollectionUtils.size(list.elements())); list.add("b"); assertEquals(2, CollectionUtils.size(list.elements())); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test public void testSize_Iterator() { final List<String> list = new ArrayList<String>(); assertEquals(0, CollectionUtils.size(list.iterator())); list.add("a"); assertEquals(1, CollectionUtils.size(list.iterator())); list.add("b"); assertEquals(2, CollectionUtils.size(list.iterator())); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }
@Test(expected=IllegalArgumentException.class) public void testSize_Other() { CollectionUtils.size("not a list"); }
public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); }
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total = IterableUtils.size((Iterable<?>) object); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator<?>) { total = IteratorUtils.size((Iterator<?>) object); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object; while (it.hasMoreElements()) { total++; it.nextElement(); } } else { try { total = Array.getLength(object); } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } return total; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyIfNull(final Collection<T> collection); static Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b); static Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b, final Predicate<O> p); static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2); static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2); static Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll); static boolean isSubCollection(final Collection<?> a, final Collection<?> b); static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<?> a, final Collection<?> b); static boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b, final Equator<? super E> equator); @Deprecated static int cardinality(final O obj, final Iterable<? super O> coll); @Deprecated static T find(final Iterable<T> collection, final Predicate<? super T> predicate); @Deprecated static C forAllDo(final Iterable<T> collection, final C closure); @Deprecated static C forAllDo(final Iterator<T> iterator, final C closure); @Deprecated static T forAllButLastDo(final Iterable<T> collection, final C closure); @Deprecated static T forAllButLastDo(final Iterator<T> iterator, final C closure); static boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate); static boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate); static void transform(final Collection<C> collection, final Transformer<? super C, ? extends C> transformer); @Deprecated static int countMatches(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean exists(final Iterable<C> input, final Predicate<? super C> predicate); @Deprecated static boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate); static Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, R outputCollection, R rejectedCollection); static Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate); static R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection); static Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer); static Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer); static R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static R collect(final Iterator<? extends I> inputIterator, final Transformer<? super I, ? extends O> transformer, final R outputCollection); static boolean addIgnoreNull(final Collection<T> collection, final T object); static boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable); static boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator); static boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration); static boolean addAll(final Collection<C> collection, final C[] elements); @Deprecated static T get(final Iterator<T> iterator, final int index); @Deprecated static T get(final Iterable<T> iterable, final int index); static Object get(final Object object, final int index); static Map.Entry<K, V> get(final Map<K,V> map, final int index); static int size(final Object object); static boolean sizeIsEmpty(final Object object); static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static void reverseArray(final Object[] array); static boolean isFull(final Collection<? extends Object> coll); static int maxSize(final Collection<? extends Object> coll); static List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c); static List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c, final boolean includeDuplicates); static Collection<List<E>> permutations(final Collection<E> collection); static Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain); static Collection<E> retainAll(final Iterable<E> collection, final Iterable<? extends E> retain, final Equator<? super E> equator); static Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove); static Collection<E> removeAll(final Iterable<E> collection, final Iterable<? extends E> remove, final Equator<? super E> equator); @Deprecated static Collection<C> synchronizedCollection(final Collection<C> collection); @Deprecated static Collection<C> unmodifiableCollection(final Collection<? extends C> collection); static Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate); static Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer); static E extractSingleton(final Collection<E> collection); @SuppressWarnings("rawtypes") // we deliberately use the raw type here static final Collection EMPTY_COLLECTION; }