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 testSizeIsEmpty_Null() { assertEquals(true, CollectionUtils.sizeIsEmpty(null)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testSizeIsEmpty_List() { final List<String> list = new ArrayList<String>(); assertEquals(true, CollectionUtils.sizeIsEmpty(list)); list.add("a"); assertEquals(false, CollectionUtils.sizeIsEmpty(list)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testSizeIsEmpty_Map() { final Map<String, String> map = new HashMap<String, String>(); assertEquals(true, CollectionUtils.sizeIsEmpty(map)); map.put("1", "a"); assertEquals(false, CollectionUtils.sizeIsEmpty(map)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testSizeIsEmpty_Array() { final Object[] objectArray = new Object[0]; assertEquals(true, CollectionUtils.sizeIsEmpty(objectArray)); final String[] stringArray = new String[3]; assertEquals(false, CollectionUtils.sizeIsEmpty(stringArray)); stringArray[0] = "a"; stringArray[1] = "b"; stringArray[2] = "c"; assertEquals(false, CollectionUtils.sizeIsEmpty(stringArray)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testSizeIsEmpty_PrimitiveArray() { final int[] intArray = new int[0]; assertEquals(true, CollectionUtils.sizeIsEmpty(intArray)); final double[] doubleArray = new double[3]; assertEquals(false, CollectionUtils.sizeIsEmpty(doubleArray)); doubleArray[0] = 0.0d; doubleArray[1] = 1.0d; doubleArray[2] = 2.5d; assertEquals(false, CollectionUtils.sizeIsEmpty(doubleArray)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testQuerySet() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Set<User>> rt = new TypeToken<Set<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> Set<T> queryForSet(DataSource ds, BoundSql boundSql, SetSupplier setSupplier, 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 testGetTypes() throws Exception { TypeToken<HashMap<String, Integer>> t = new TypeToken<HashMap<String, Integer>>() { }; Set<TypeToken<?>> types = t.getTypes(); assertThat(types.size(), equalTo(6)); types.contains(new TypeToken<Map<String, Integer>>() { }); types.contains(new TypeToken<HashMap<String, Integer>>() { }); types.contains(new TypeToken<AbstractMap<String, Integer>>() { }); types.contains(TypeToken.of(Cloneable.class)); types.contains(TypeToken.of(Serializable.class)); types.contains(TypeToken.of(Object.class)); }
Set<TypeToken<?>> getTypes() { Set<TypeToken<?>> tokens = new HashSet<TypeToken<?>>(); tokens.add(this); TypeToken<?> superclass = getGenericSuperclass(); if (superclass != null) { tokens.add(superclass); tokens.addAll(superclass.getTypes()); } List<TypeToken<?>> interfaces = getGenericInterfaces(); for (TypeToken<?> anInterface : interfaces) { tokens.add(anInterface); tokens.addAll(anInterface.getTypes()); } return tokens; }
TypeToken extends TypeCapture<T> implements Serializable { Set<TypeToken<?>> getTypes() { Set<TypeToken<?>> tokens = new HashSet<TypeToken<?>>(); tokens.add(this); TypeToken<?> superclass = getGenericSuperclass(); if (superclass != null) { tokens.add(superclass); tokens.addAll(superclass.getTypes()); } List<TypeToken<?>> interfaces = getGenericInterfaces(); for (TypeToken<?> anInterface : interfaces) { tokens.add(anInterface); tokens.addAll(anInterface.getTypes()); } return tokens; } }
TypeToken extends TypeCapture<T> implements Serializable { Set<TypeToken<?>> getTypes() { Set<TypeToken<?>> tokens = new HashSet<TypeToken<?>>(); tokens.add(this); TypeToken<?> superclass = getGenericSuperclass(); if (superclass != null) { tokens.add(superclass); tokens.addAll(superclass.getTypes()); } List<TypeToken<?>> interfaces = getGenericInterfaces(); for (TypeToken<?> anInterface : interfaces) { tokens.add(anInterface); tokens.addAll(anInterface.getTypes()); } return tokens; } protected TypeToken(); private TypeToken(Type type); }
TypeToken extends TypeCapture<T> implements Serializable { Set<TypeToken<?>> getTypes() { Set<TypeToken<?>> tokens = new HashSet<TypeToken<?>>(); tokens.add(this); TypeToken<?> superclass = getGenericSuperclass(); if (superclass != null) { tokens.add(superclass); tokens.addAll(superclass.getTypes()); } List<TypeToken<?>> interfaces = getGenericInterfaces(); for (TypeToken<?> anInterface : interfaces) { tokens.add(anInterface); tokens.addAll(anInterface.getTypes()); } return tokens; } protected TypeToken(); private TypeToken(Type type); static TypeToken<T> of(Class<T> type); static TypeToken<?> of(Type type); final Class<? super T> getRawType(); final Type getType(); final TypeToken<T> where(TypeParameter<X> typeParam, TypeToken<X> typeArg); final TypeToken<?> resolveType(Type type); final boolean isAssignableFrom(TypeToken<?> type); final boolean isAssignableFrom(Type type); final boolean isArray(); final boolean isPrimitive(); final TypeToken<T> wrap(); @Nullable final TypeToken<?> getComponentType(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); TypeToken<?> resolveFatherClass(Class<?> clazz); TokenTuple resolveFatherClassTuple(Class<?> clazz); }
TypeToken extends TypeCapture<T> implements Serializable { Set<TypeToken<?>> getTypes() { Set<TypeToken<?>> tokens = new HashSet<TypeToken<?>>(); tokens.add(this); TypeToken<?> superclass = getGenericSuperclass(); if (superclass != null) { tokens.add(superclass); tokens.addAll(superclass.getTypes()); } List<TypeToken<?>> interfaces = getGenericInterfaces(); for (TypeToken<?> anInterface : interfaces) { tokens.add(anInterface); tokens.addAll(anInterface.getTypes()); } return tokens; } protected TypeToken(); private TypeToken(Type type); static TypeToken<T> of(Class<T> type); static TypeToken<?> of(Type type); final Class<? super T> getRawType(); final Type getType(); final TypeToken<T> where(TypeParameter<X> typeParam, TypeToken<X> typeArg); final TypeToken<?> resolveType(Type type); final boolean isAssignableFrom(TypeToken<?> type); final boolean isAssignableFrom(Type type); final boolean isArray(); final boolean isPrimitive(); final TypeToken<T> wrap(); @Nullable final TypeToken<?> getComponentType(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); TypeToken<?> resolveFatherClass(Class<?> clazz); TokenTuple resolveFatherClassTuple(Class<?> clazz); }
@Test public void testSizeIsEmpty_Enumeration() { final Vector<String> list = new Vector<String>(); assertEquals(true, CollectionUtils.sizeIsEmpty(list.elements())); list.add("a"); assertEquals(false, CollectionUtils.sizeIsEmpty(list.elements())); final Enumeration<String> en = list.elements(); en.nextElement(); assertEquals(true, CollectionUtils.sizeIsEmpty(en)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testSizeIsEmpty_Iterator() { final List<String> list = new ArrayList<String>(); assertEquals(true, CollectionUtils.sizeIsEmpty(list.iterator())); list.add("a"); assertEquals(false, CollectionUtils.sizeIsEmpty(list.iterator())); final Iterator<String> it = list.iterator(); it.next(); assertEquals(true, CollectionUtils.sizeIsEmpty(it)); }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testSizeIsEmpty_Other() { try { CollectionUtils.sizeIsEmpty("not a list"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } }
public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } private CollectionUtils(); }
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanceof Map<?, ?>) { return ((Map<?, ?>) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator<?>) { return ((Iterator<?>) object).hasNext() == false; } else if (object instanceof Enumeration<?>) { return ((Enumeration<?>) object).hasMoreElements() == false; } else { try { return Array.getLength(object) == 0; } catch (final IllegalArgumentException ex) { throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName()); } } } 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 testIsEmptyWithEmptyCollection() { final Collection<Object> coll = new ArrayList<Object>(); assertEquals(true, CollectionUtils.isEmpty(coll)); }
public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } private CollectionUtils(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 testIsEmptyWithNonEmptyCollection() { final Collection<String> coll = new ArrayList<String>(); coll.add("item"); assertEquals(false, CollectionUtils.isEmpty(coll)); }
public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } private CollectionUtils(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 testIsEmptyWithNull() { final Collection<?> coll = null; assertEquals(true, CollectionUtils.isEmpty(coll)); }
public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } private CollectionUtils(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 testIsNotEmptyWithEmptyCollection() { final Collection<Object> coll = new ArrayList<Object>(); assertEquals(false, CollectionUtils.isNotEmpty(coll)); }
public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } private CollectionUtils(); }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } 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 isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } 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 testIsNotEmptyWithNonEmptyCollection() { final Collection<String> coll = new ArrayList<String>(); coll.add("item"); assertEquals(true, CollectionUtils.isNotEmpty(coll)); }
public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } private CollectionUtils(); }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } 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 isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } 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 testIsNotEmptyWithNull() { final Collection<?> coll = null; assertEquals(false, CollectionUtils.isNotEmpty(coll)); }
public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } private CollectionUtils(); }
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } 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 isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } 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 filter() { final List<Integer> ints = new ArrayList<Integer>(); ints.add(1); ints.add(2); ints.add(3); ints.add(3); final Iterable<Integer> iterable = ints; assertTrue(CollectionUtils.filter(iterable, EQUALS_TWO)); assertEquals(1, ints.size()); assertEquals(2, (int) ints.get(0)); }
public static <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) { boolean result = false; if (collection != null && predicate != null) { for (final Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); result = true; } } } return result; }
CollectionUtils { public static <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) { boolean result = false; if (collection != null && predicate != null) { for (final Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); result = true; } } } return result; } }
CollectionUtils { public static <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) { boolean result = false; if (collection != null && predicate != null) { for (final Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); result = true; } } } return result; } private CollectionUtils(); }
CollectionUtils { public static <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) { boolean result = false; if (collection != null && predicate != null) { for (final Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); result = true; } } } return result; } 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 <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) { boolean result = false; if (collection != null && predicate != null) { for (final Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); result = true; } } } return result; } 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 testQueryArray() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<User[]> rt = TypeToken.of(User[].class); 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> Object queryForArray(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 filterInverse() { final List<Integer> ints = new ArrayList<Integer>(); ints.add(1); ints.add(2); ints.add(3); ints.add(3); final Iterable<Integer> iterable = ints; assertTrue(CollectionUtils.filterInverse(iterable, EQUALS_TWO)); assertEquals(3, ints.size()); assertEquals(1, (int) ints.get(0)); assertEquals(3, (int) ints.get(1)); assertEquals(3, (int) ints.get(2)); }
public static <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) { return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate)); }
CollectionUtils { public static <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) { return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate)); } }
CollectionUtils { public static <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) { return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate)); } private CollectionUtils(); }
CollectionUtils { public static <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) { return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate)); } 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 <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) { return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate)); } 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 countMatches() { assertEquals(4, CollectionUtils.countMatches(iterableB, EQUALS_TWO)); assertEquals(0, CollectionUtils.countMatches(iterableA, null)); assertEquals(0, CollectionUtils.countMatches(null, EQUALS_TWO)); assertEquals(0, CollectionUtils.countMatches(null, null)); }
@Deprecated public static <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? 0 : (int) IterableUtils.countMatches(input, predicate); }
CollectionUtils { @Deprecated public static <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? 0 : (int) IterableUtils.countMatches(input, predicate); } }
CollectionUtils { @Deprecated public static <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? 0 : (int) IterableUtils.countMatches(input, predicate); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? 0 : (int) IterableUtils.countMatches(input, predicate); } 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 <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? 0 : (int) IterableUtils.countMatches(input, predicate); } 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 exists() { final List<Integer> list = new ArrayList<Integer>(); assertFalse(CollectionUtils.exists(null, null)); assertFalse(CollectionUtils.exists(list, null)); assertFalse(CollectionUtils.exists(null, EQUALS_TWO)); assertFalse(CollectionUtils.exists(list, EQUALS_TWO)); list.add(1); list.add(3); list.add(4); assertFalse(CollectionUtils.exists(list, EQUALS_TWO)); list.add(2); assertEquals(true, CollectionUtils.exists(list, EQUALS_TWO)); }
@Deprecated public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAny(input, predicate); }
CollectionUtils { @Deprecated public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAny(input, predicate); } }
CollectionUtils { @Deprecated public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAny(input, predicate); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAny(input, predicate); } 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 <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAny(input, predicate); } 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 select() { final List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); list.add(4); final Collection<Integer> output1 = CollectionUtils.select(list, EQUALS_TWO); final Collection<Number> output2 = CollectionUtils.<Number>select(list, EQUALS_TWO); final HashSet<Number> output3 = CollectionUtils.select(list, EQUALS_TWO, new HashSet<Number>()); assertTrue(CollectionUtils.isEqualCollection(output1, output3)); assertEquals(4, list.size()); assertEquals(1, output1.size()); assertEquals(2, output2.iterator().next()); }
public static <O> Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return select(inputCollection, predicate, answer); }
CollectionUtils { public static <O> Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return select(inputCollection, predicate, answer); } }
CollectionUtils { public static <O> Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return select(inputCollection, predicate, answer); } private CollectionUtils(); }
CollectionUtils { public static <O> Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return select(inputCollection, predicate, answer); } 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> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return select(inputCollection, predicate, answer); } 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 selectRejected() { final List<Long> list = new ArrayList<Long>(); list.add(1L); list.add(2L); list.add(3L); list.add(4L); final Collection<Long> output1 = CollectionUtils.selectRejected(list, EQUALS_TWO); final Collection<? extends Number> output2 = CollectionUtils.selectRejected(list, EQUALS_TWO); final HashSet<Number> output3 = CollectionUtils.selectRejected(list, EQUALS_TWO, new HashSet<Number>()); assertTrue(CollectionUtils.isEqualCollection(output1, output2)); assertTrue(CollectionUtils.isEqualCollection(output1, output3)); assertEquals(4, list.size()); assertEquals(3, output1.size()); assertTrue(output1.contains(1L)); assertTrue(output1.contains(3L)); assertTrue(output1.contains(4L)); }
public static <O> Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return selectRejected(inputCollection, predicate, answer); }
CollectionUtils { public static <O> Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return selectRejected(inputCollection, predicate, answer); } }
CollectionUtils { public static <O> Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return selectRejected(inputCollection, predicate, answer); } private CollectionUtils(); }
CollectionUtils { public static <O> Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return selectRejected(inputCollection, predicate, answer); } 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> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return selectRejected(inputCollection, predicate, answer); } 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 collect() { final Transformer<Number, Long> transformer = TransformerUtils.constantTransformer(2L); Collection<Number> collection = CollectionUtils.<Integer, Number>collect(iterableA, transformer); assertTrue(collection.size() == collectionA.size()); assertCollectResult(collection); ArrayList<Number> list; list = CollectionUtils.collect(collectionA, transformer, new ArrayList<Number>()); assertTrue(list.size() == collectionA.size()); assertCollectResult(list); Iterator<Integer> iterator = null; list = CollectionUtils.collect(iterator, transformer, new ArrayList<Number>()); iterator = iterableA.iterator(); list = CollectionUtils.collect(iterator, transformer, list); assertTrue(collection.size() == collectionA.size()); assertCollectResult(collection); iterator = collectionA.iterator(); collection = CollectionUtils.<Integer, Number>collect(iterator, transformer); assertTrue(collection.size() == collectionA.size()); assertTrue(collection.contains(2L) && !collection.contains(1)); collection = CollectionUtils.collect((Iterator<Integer>) null, (Transformer<Integer, Number>) null); assertTrue(collection.size() == 0); final int size = collectionA.size(); collectionB = CollectionUtils.collect((Collection<Integer>) null, transformer, collectionB); assertTrue(collectionA.size() == size && collectionA.contains(1)); CollectionUtils.collect(collectionB, null, collectionA); assertTrue(collectionA.size() == size && collectionA.contains(1)); }
public static <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); }
CollectionUtils { public static <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); } }
CollectionUtils { public static <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); } private CollectionUtils(); }
CollectionUtils { public static <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); } 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 <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); } 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 addIgnoreNull() { final Set<String> set = new HashSet<String>(); set.add("1"); set.add("2"); set.add("3"); assertFalse(CollectionUtils.addIgnoreNull(set, null)); assertEquals(3, set.size()); assertFalse(CollectionUtils.addIgnoreNull(set, "1")); assertEquals(3, set.size()); assertEquals(true, CollectionUtils.addIgnoreNull(set, "4")); assertEquals(4, set.size()); assertEquals(true, set.contains("4")); }
public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); }
CollectionUtils { public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); } }
CollectionUtils { public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); } private CollectionUtils(); }
CollectionUtils { public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); } 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 <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); } 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 predicatedCollection() { final Predicate<Object> predicate = PredicateUtils.instanceofPredicate(Integer.class); Collection<Number> collection = CollectionUtils.predicatedCollection(new ArrayList<Number>(), predicate); assertTrue("returned object should be a PredicatedCollection", collection instanceof PredicatedCollection); try { CollectionUtils.predicatedCollection(new ArrayList<Number>(), null); fail("Expecting NullPointerException for null predicate."); } catch (final NullPointerException ex) { } try { CollectionUtils.predicatedCollection(null, predicate); fail("Expecting NullPointerException for null collection."); } catch (final NullPointerException ex) { } }
public static <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) { return PredicatedCollection.predicatedCollection(collection, predicate); }
CollectionUtils { public static <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) { return PredicatedCollection.predicatedCollection(collection, predicate); } }
CollectionUtils { public static <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) { return PredicatedCollection.predicatedCollection(collection, predicate); } private CollectionUtils(); }
CollectionUtils { public static <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) { return PredicatedCollection.predicatedCollection(collection, predicate); } 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 <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) { return PredicatedCollection.predicatedCollection(collection, predicate); } 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 isFull() { final Set<String> set = new HashSet<String>(); set.add("1"); set.add("2"); set.add("3"); try { CollectionUtils.isFull(null); fail(); } catch (final NullPointerException ex) { } assertFalse(CollectionUtils.isFull(set)); final CircularFifoQueue<String> buf = new CircularFifoQueue<String>(set); assertEquals(false, CollectionUtils.isFull(buf)); buf.remove("2"); assertFalse(CollectionUtils.isFull(buf)); buf.add("2"); assertEquals(false, CollectionUtils.isFull(buf)); }
public static boolean isFull(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).isFull(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.isFull(); } catch (final IllegalArgumentException ex) { return false; } }
CollectionUtils { public static boolean isFull(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).isFull(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.isFull(); } catch (final IllegalArgumentException ex) { return false; } } }
CollectionUtils { public static boolean isFull(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).isFull(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.isFull(); } catch (final IllegalArgumentException ex) { return false; } } private CollectionUtils(); }
CollectionUtils { public static boolean isFull(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).isFull(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.isFull(); } catch (final IllegalArgumentException ex) { 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 isFull(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).isFull(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.isFull(); } catch (final IllegalArgumentException ex) { 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 isEmpty() { assertFalse(CollectionUtils.isNotEmpty(null)); assertTrue(CollectionUtils.isNotEmpty(collectionA)); }
public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } private CollectionUtils(); }
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } 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 testQueryIn() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<List<User>> rt = new TypeToken<List<User>>() { }; String srcSql = "select * from user where id in (:1)"; 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 in (?,?,?)"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(3)); assertThat(args[0], equalTo((Object) 100)); assertThat(args[1], equalTo((Object) 200)); assertThat(args[2], equalTo((Object) 300)); assertThat(rowMapper.getMappedClass().equals(User.class), is(true)); return null; } }); List<Integer> ids = Arrays.asList(100, 200, 300); operator.execute(new Object[]{ids}, 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 maxSize() { final Set<String> set = new HashSet<String>(); set.add("1"); set.add("2"); set.add("3"); try { CollectionUtils.maxSize(null); fail(); } catch (final NullPointerException ex) { } assertEquals(-1, CollectionUtils.maxSize(set)); final Queue<String> buf = new CircularFifoQueue<String>(set); assertEquals(3, CollectionUtils.maxSize(buf)); buf.remove("2"); assertEquals(3, CollectionUtils.maxSize(buf)); buf.add("2"); assertEquals(3, CollectionUtils.maxSize(buf)); }
public static int maxSize(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).maxSize(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.maxSize(); } catch (final IllegalArgumentException ex) { return -1; } }
CollectionUtils { public static int maxSize(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).maxSize(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.maxSize(); } catch (final IllegalArgumentException ex) { return -1; } } }
CollectionUtils { public static int maxSize(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).maxSize(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.maxSize(); } catch (final IllegalArgumentException ex) { return -1; } } private CollectionUtils(); }
CollectionUtils { public static int maxSize(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).maxSize(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.maxSize(); } catch (final IllegalArgumentException ex) { return -1; } } 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 maxSize(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).maxSize(); } try { final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); return bcoll.maxSize(); } catch (final IllegalArgumentException ex) { return -1; } } 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 testRetainAll() { final List<String> base = new ArrayList<String>(); base.add("A"); base.add("B"); base.add("C"); final List<Object> sub = new ArrayList<Object>(); sub.add("A"); sub.add("C"); sub.add("X"); final Collection<String> result = CollectionUtils.retainAll(base, sub); assertEquals(2, result.size()); assertEquals(true, result.contains("A")); assertFalse(result.contains("B")); assertEquals(true, result.contains("C")); assertEquals(3, base.size()); assertEquals(true, base.contains("A")); assertEquals(true, base.contains("B")); assertEquals(true, base.contains("C")); assertEquals(3, sub.size()); assertEquals(true, sub.contains("A")); assertEquals(true, sub.contains("C")); assertEquals(true, sub.contains("X")); try { CollectionUtils.retainAll(null, null); fail("expecting NullPointerException"); } catch (final NullPointerException npe) { } }
public static <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) { return ListUtils.retainAll(collection, retain); }
CollectionUtils { public static <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) { return ListUtils.retainAll(collection, retain); } }
CollectionUtils { public static <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) { return ListUtils.retainAll(collection, retain); } private CollectionUtils(); }
CollectionUtils { public static <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) { return ListUtils.retainAll(collection, retain); } 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 <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) { return ListUtils.retainAll(collection, retain); } 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 testRemoveAll() { final List<String> base = new ArrayList<String>(); base.add("A"); base.add("B"); base.add("C"); final List<String> sub = new ArrayList<String>(); sub.add("A"); sub.add("C"); sub.add("X"); final Collection<String> result = CollectionUtils.removeAll(base, sub); assertEquals(1, result.size()); assertFalse(result.contains("A")); assertEquals(true, result.contains("B")); assertFalse(result.contains("C")); assertEquals(3, base.size()); assertEquals(true, base.contains("A")); assertEquals(true, base.contains("B")); assertEquals(true, base.contains("C")); assertEquals(3, sub.size()); assertEquals(true, sub.contains("A")); assertEquals(true, sub.contains("C")); assertEquals(true, sub.contains("X")); try { CollectionUtils.removeAll(null, null); fail("expecting NullPointerException"); } catch (final NullPointerException npe) { } }
public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) { return ListUtils.removeAll(collection, remove); }
CollectionUtils { public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) { return ListUtils.removeAll(collection, remove); } }
CollectionUtils { public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) { return ListUtils.removeAll(collection, remove); } private CollectionUtils(); }
CollectionUtils { public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) { return ListUtils.removeAll(collection, remove); } 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 <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) { return ListUtils.removeAll(collection, remove); } 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 testTransformedCollection() { final Transformer<Object, Object> transformer = TransformerUtils.nopTransformer(); Collection<Object> collection = CollectionUtils.transformingCollection(new ArrayList<Object>(), transformer); assertTrue("returned object should be a TransformedCollection", collection instanceof TransformedCollection); try { CollectionUtils.transformingCollection(new ArrayList<Object>(), null); fail("Expecting NullPointerException for null transformer."); } catch (final NullPointerException ex) { } try { CollectionUtils.transformingCollection(null, transformer); fail("Expecting NullPointerException for null collection."); } catch (final NullPointerException ex) { } }
public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); }
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } }
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } private CollectionUtils(); }
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } 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 <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } 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 testTransformedCollection_2() { final List<Object> list = new ArrayList<Object>(); list.add("1"); list.add("2"); list.add("3"); final Collection<Object> result = CollectionUtils.transformingCollection(list, TRANSFORM_TO_INTEGER); assertEquals(true, result.contains("1")); assertEquals(true, result.contains("2")); assertEquals(true, result.contains("3")); }
public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); }
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } }
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } private CollectionUtils(); }
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } 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 <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } 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 testSynchronizedCollection() { Collection<Object> col = CollectionUtils.synchronizedCollection(new ArrayList<Object>()); assertTrue("Returned object should be a SynchronizedCollection.", col instanceof SynchronizedCollection); try { CollectionUtils.synchronizedCollection(null); fail("Expecting NullPointerException for null collection."); } catch (final NullPointerException ex) { } }
@Deprecated public static <C> Collection<C> synchronizedCollection(final Collection<C> collection) { return SynchronizedCollection.synchronizedCollection(collection); }
CollectionUtils { @Deprecated public static <C> Collection<C> synchronizedCollection(final Collection<C> collection) { return SynchronizedCollection.synchronizedCollection(collection); } }
CollectionUtils { @Deprecated public static <C> Collection<C> synchronizedCollection(final Collection<C> collection) { return SynchronizedCollection.synchronizedCollection(collection); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <C> Collection<C> synchronizedCollection(final Collection<C> collection) { return SynchronizedCollection.synchronizedCollection(collection); } 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 <C> Collection<C> synchronizedCollection(final Collection<C> collection) { return SynchronizedCollection.synchronizedCollection(collection); } 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 testUnmodifiableCollection() { Collection<Object> col = CollectionUtils.unmodifiableCollection(new ArrayList<Object>()); assertTrue("Returned object should be a UnmodifiableCollection.", col instanceof UnmodifiableCollection); try { CollectionUtils.unmodifiableCollection(null); fail("Expecting NullPointerException for null collection."); } catch (final NullPointerException ex) { } }
@Deprecated public static <C> Collection<C> unmodifiableCollection(final Collection<? extends C> collection) { return UnmodifiableCollection.unmodifiableCollection(collection); }
CollectionUtils { @Deprecated public static <C> Collection<C> unmodifiableCollection(final Collection<? extends C> collection) { return UnmodifiableCollection.unmodifiableCollection(collection); } }
CollectionUtils { @Deprecated public static <C> Collection<C> unmodifiableCollection(final Collection<? extends C> collection) { return UnmodifiableCollection.unmodifiableCollection(collection); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <C> Collection<C> unmodifiableCollection(final Collection<? extends C> collection) { return UnmodifiableCollection.unmodifiableCollection(collection); } 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 <C> Collection<C> unmodifiableCollection(final Collection<? extends C> collection) { return UnmodifiableCollection.unmodifiableCollection(collection); } 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 emptyCollection() throws Exception { final Collection<Number> coll = CollectionUtils.emptyCollection(); assertEquals(CollectionUtils.EMPTY_COLLECTION, coll); }
@SuppressWarnings("unchecked") public static <T> Collection<T> emptyCollection() { return EMPTY_COLLECTION; }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyCollection() { return EMPTY_COLLECTION; } }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyCollection() { return EMPTY_COLLECTION; } private CollectionUtils(); }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyCollection() { return EMPTY_COLLECTION; } 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 { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyCollection() { return EMPTY_COLLECTION; } 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 emptyIfNull() { assertTrue(CollectionUtils.emptyIfNull(null).isEmpty()); final Collection<Object> collection = new ArrayList<Object>(); assertSame(collection, CollectionUtils.emptyIfNull(collection)); }
@SuppressWarnings("unchecked") public static <T> Collection<T> emptyIfNull(final Collection<T> collection) { return collection == null ? EMPTY_COLLECTION : collection; }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyIfNull(final Collection<T> collection) { return collection == null ? EMPTY_COLLECTION : collection; } }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyIfNull(final Collection<T> collection) { return collection == null ? EMPTY_COLLECTION : collection; } private CollectionUtils(); }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyIfNull(final Collection<T> collection) { return collection == null ? EMPTY_COLLECTION : collection; } 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 { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyIfNull(final Collection<T> collection) { return collection == null ? EMPTY_COLLECTION : collection; } 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 addAllForIterable() { final Collection<Integer> inputCollection = createMock(Collection.class); final Iterable<Integer> inputIterable = inputCollection; final Iterable<Long> iterable = createMock(Iterable.class); final Iterator<Long> iterator = createMock(Iterator.class); final Collection<Number> c = createMock(Collection.class); expect(iterable.iterator()).andReturn(iterator); next(iterator, 1L); next(iterator, 2L); next(iterator, 3L); expect(iterator.hasNext()).andReturn(false); expect(c.add(1L)).andReturn(true); expect(c.add(2L)).andReturn(true); expect(c.add(3L)).andReturn(true); expect(c.addAll(inputCollection)).andReturn(true); expect(iterable.iterator()).andReturn(iterator); next(iterator, 1L); expect(iterator.hasNext()).andReturn(false); expect(c.add(1L)).andReturn(false); expect(c.addAll(inputCollection)).andReturn(false); replay(); assertTrue(CollectionUtils.addAll(c, iterable)); assertTrue(CollectionUtils.addAll(c, inputIterable)); assertFalse(CollectionUtils.addAll(c, iterable)); assertFalse(CollectionUtils.addAll(c, inputIterable)); verify(); }
public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } private CollectionUtils(); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } 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 <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } 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 testQueryInCount() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<Integer> rt = new TypeToken<Integer>() { }; String srcSql = "select count(1) from user where id in (:1)"; AbstractOperator operator = getOperator(pt, rt, srcSql, new ArrayList<Annotation>()); operator.setJdbcOperations(new JdbcOperationsAdapter() { @SuppressWarnings("unchecked") @Override public <T> T queryForObject(DataSource ds, BoundSql boundSql, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select count(1) from user where id in (?,?,?)"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(3)); assertThat(args[0], equalTo((Object) 100)); assertThat(args[1], equalTo((Object) 200)); assertThat(args[2], equalTo((Object) 300)); assertThat(rowMapper.getMappedClass().equals(Integer.class), is(true)); return (T) Integer.valueOf(3); } }); List<Integer> ids = Arrays.asList(100, 200, 300); Integer r = (Integer) operator.execute(new Object[]{ids}, InvocationStat.create()); assertThat(r, is(3)); }
@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 addAllForEnumeration() { final Hashtable<Integer, Integer> h = new Hashtable<Integer, Integer>(); h.put(5, 5); final Enumeration<? extends Integer> enumeration = h.keys(); CollectionUtils.addAll(collectionA, enumeration); assertTrue(collectionA.contains(5)); }
public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } private CollectionUtils(); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } 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 <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } 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 addAllForElements() { CollectionUtils.addAll(collectionA, new Integer[]{5}); assertTrue(collectionA.contains(5)); }
public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } private CollectionUtils(); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } 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 <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } 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 getNegative() { CollectionUtils.get((Object)collectionA, -3); }
@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 getPositiveOutOfBounds() { CollectionUtils.get((Object)collectionA.iterator(), 30); }
@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 get1() { CollectionUtils.get((Object)null, 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 get() { assertEquals(2, CollectionUtils.get((Object)collectionA, 2)); assertEquals(2, CollectionUtils.get((Object)collectionA.iterator(), 2)); final Map<Integer, Integer> map = CollectionUtils.getCardinalityMap(collectionA); assertEquals(map.entrySet().iterator().next(), CollectionUtils.get((Object)map, 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 getIterator() { final Iterator<Integer> it = collectionA.iterator(); assertEquals(Integer.valueOf(2), CollectionUtils.get((Object) it, 2)); assertTrue(it.hasNext()); assertEquals(Integer.valueOf(4), CollectionUtils.get((Object) it, 6)); assertFalse(it.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 public void getEnumeration() { final Vector<Integer> vectorA = new Vector<Integer>(collectionA); final Enumeration<Integer> e = vectorA.elements(); assertEquals(Integer.valueOf(2), CollectionUtils.get(e, 2)); assertTrue(e.hasMoreElements()); assertEquals(Integer.valueOf(4), CollectionUtils.get(e, 6)); assertFalse(e.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 public void extractSingleton() { ArrayList<String> coll = null; try { CollectionUtils.extractSingleton(coll); fail("expected NullPointerException from extractSingleton(null)"); } catch (final NullPointerException e) { } coll = new ArrayList<String>(); try { CollectionUtils.extractSingleton(coll); fail("expected IllegalArgumentException from extractSingleton(empty)"); } catch (final IllegalArgumentException e) { } coll.add("foo"); assertEquals("foo", CollectionUtils.extractSingleton(coll)); coll.add("bar"); try { CollectionUtils.extractSingleton(coll); fail("expected IllegalArgumentException from extractSingleton(size == 2)"); } catch (final IllegalArgumentException e) { } }
public static <E> E extractSingleton(final Collection<E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null."); } if (collection.size() != 1) { throw new IllegalArgumentException("Can extract singleton only when collection size == 1"); } return collection.iterator().next(); }
CollectionUtils { public static <E> E extractSingleton(final Collection<E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null."); } if (collection.size() != 1) { throw new IllegalArgumentException("Can extract singleton only when collection size == 1"); } return collection.iterator().next(); } }
CollectionUtils { public static <E> E extractSingleton(final Collection<E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null."); } if (collection.size() != 1) { throw new IllegalArgumentException("Can extract singleton only when collection size == 1"); } return collection.iterator().next(); } private CollectionUtils(); }
CollectionUtils { public static <E> E extractSingleton(final Collection<E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null."); } if (collection.size() != 1) { throw new IllegalArgumentException("Can extract singleton only when collection size == 1"); } return collection.iterator().next(); } 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 <E> E extractSingleton(final Collection<E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null."); } if (collection.size() != 1) { throw new IllegalArgumentException("Can extract singleton only when collection size == 1"); } return collection.iterator().next(); } 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 collateException1() { CollectionUtils.collate(collectionA, null); }
public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } private CollectionUtils(); }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), 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 <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), 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 testStatsCounter() 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>()); User user = new User(); user.setId(100); user.setName("ash"); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> T queryForObject(DataSource ds, BoundSql boundSql, RowMapper<T> rowMapper) { return null; } }); 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); }
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(expected=NullPointerException.class) public void collateException2() { CollectionUtils.collate(collectionA, collectionC, null); }
public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } private CollectionUtils(); }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), 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 <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), 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 testCollate() { List<Integer> result = CollectionUtils.collate(emptyCollection, emptyCollection); assertEquals("Merge empty with empty", 0, result.size()); result = CollectionUtils.collate(collectionA, emptyCollection); assertEquals("Merge empty with non-empty", collectionA, result); List<Integer> result1 = CollectionUtils.collate(collectionD, collectionE); List<Integer> result2 = CollectionUtils.collate(collectionE, collectionD); assertEquals("Merge two lists 1", result1, result2); List<Integer> combinedList = new ArrayList<Integer>(); combinedList.addAll(collectionD); combinedList.addAll(collectionE); Collections.sort(combinedList); assertEquals("Merge two lists 2", combinedList, result2); final Comparator<Integer> reverseComparator = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); result = CollectionUtils.collate(emptyCollection, emptyCollection, reverseComparator); assertEquals("Comparator Merge empty with empty", 0, result.size()); Collections.reverse((List<Integer>) collectionD); Collections.reverse((List<Integer>) collectionE); Collections.reverse(combinedList); result1 = CollectionUtils.collate(collectionD, collectionE, reverseComparator); result2 = CollectionUtils.collate(collectionE, collectionD, reverseComparator); assertEquals("Comparator Merge two lists 1", result1, result2); assertEquals("Comparator Merge two lists 2", combinedList, result2); }
public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } private CollectionUtils(); }
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), 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 <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), 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 testPermutationsWithNullCollection() { CollectionUtils.permutations(null); }
public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; }
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } }
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } private CollectionUtils(); }
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } 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 <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } 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 testPermutations() { List<Integer> sample = collectionA.subList(0, 5); Collection<List<Integer>> permutations = CollectionUtils.permutations(sample); int collSize = sample.size(); int factorial = 1; for (int i = 1; i <= collSize; i++) { factorial *= i; } assertEquals(factorial, permutations.size()); }
public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; }
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } }
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } private CollectionUtils(); }
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } 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 <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } 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 testMatchesAll() { assertFalse(CollectionUtils.matchesAll(null, null)); assertFalse(CollectionUtils.matchesAll(collectionA, null)); Predicate<Integer> lessThanFive = new Predicate<Integer>() { @Override public boolean evaluate(Integer object) { return object < 5; } }; assertTrue(CollectionUtils.matchesAll(collectionA, lessThanFive)); Predicate<Integer> lessThanFour = new Predicate<Integer>() { @Override public boolean evaluate(Integer object) { return object < 4; } }; assertFalse(CollectionUtils.matchesAll(collectionA, lessThanFour)); assertTrue(CollectionUtils.matchesAll(null, lessThanFour)); assertTrue(CollectionUtils.matchesAll(emptyCollection, lessThanFour)); }
@Deprecated public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAll(input, predicate); }
CollectionUtils { @Deprecated public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAll(input, predicate); } }
CollectionUtils { @Deprecated public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAll(input, predicate); } private CollectionUtils(); }
CollectionUtils { @Deprecated public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAll(input, predicate); } 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 <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAll(input, predicate); } 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 mapGet() { Map<Integer, Number> map = lazySortedMap(new TreeMap<Integer,Number>(), oneFactory); assertEquals(0, map.size()); final Number i1 = map.get(5); assertEquals(1, i1); assertEquals(1, map.size()); map = lazySortedMap(new TreeMap<Integer,Number>(), FactoryUtils.<Number>nullFactory()); final Number o = map.get(5); assertEquals(null,o); assertEquals(1, map.size()); }
public static <K, V> LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { return new LazySortedMap<K,V>(map, factory); }
LazySortedMap extends LazyMap<K,V> implements SortedMap<K,V> { public static <K, V> LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { return new LazySortedMap<K,V>(map, factory); } }
LazySortedMap extends LazyMap<K,V> implements SortedMap<K,V> { public static <K, V> LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { return new LazySortedMap<K,V>(map, factory); } protected LazySortedMap(final SortedMap<K,V> map, final Factory<? extends V> factory); protected LazySortedMap(final SortedMap<K,V> map, final Transformer<? super K, ? extends V> factory); }
LazySortedMap extends LazyMap<K,V> implements SortedMap<K,V> { public static <K, V> LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { return new LazySortedMap<K,V>(map, factory); } protected LazySortedMap(final SortedMap<K,V> map, final Factory<? extends V> factory); protected LazySortedMap(final SortedMap<K,V> map, final Transformer<? super K, ? extends V> factory); static LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory); static LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Transformer<? super K, ? extends V> factory); K firstKey(); K lastKey(); Comparator<? super K> comparator(); SortedMap<K,V> subMap(final K fromKey, final K toKey); SortedMap<K,V> headMap(final K toKey); SortedMap<K,V> tailMap(final K fromKey); }
LazySortedMap extends LazyMap<K,V> implements SortedMap<K,V> { public static <K, V> LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { return new LazySortedMap<K,V>(map, factory); } protected LazySortedMap(final SortedMap<K,V> map, final Factory<? extends V> factory); protected LazySortedMap(final SortedMap<K,V> map, final Transformer<? super K, ? extends V> factory); static LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory); static LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Transformer<? super K, ? extends V> factory); K firstKey(); K lastKey(); Comparator<? super K> comparator(); SortedMap<K,V> subMap(final K fromKey, final K toKey); SortedMap<K,V> headMap(final K toKey); SortedMap<K,V> tailMap(final K fromKey); }
@Test public void testExceptionTransformer() { assertNotNull(TransformerUtils.exceptionTransformer()); assertSame(TransformerUtils.exceptionTransformer(), TransformerUtils.exceptionTransformer()); try { TransformerUtils.exceptionTransformer().transform(null); } catch (final FunctorException ex) { try { TransformerUtils.exceptionTransformer().transform(cString); } catch (final FunctorException ex2) { return; } } fail(); }
public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); } }
TransformerUtils { public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testNullTransformer() { assertNotNull(TransformerUtils.nullTransformer()); assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer()); assertEquals(null, TransformerUtils.nullTransformer().transform(null)); assertEquals(null, TransformerUtils.nullTransformer().transform(cObject)); assertEquals(null, TransformerUtils.nullTransformer().transform(cString)); assertEquals(null, TransformerUtils.nullTransformer().transform(cInteger)); }
public static <I, O> Transformer<I, O> nullTransformer() { return ConstantTransformer.nullTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> nullTransformer() { return ConstantTransformer.nullTransformer(); } }
TransformerUtils { public static <I, O> Transformer<I, O> nullTransformer() { return ConstantTransformer.nullTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <I, O> Transformer<I, O> nullTransformer() { return ConstantTransformer.nullTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> nullTransformer() { return ConstantTransformer.nullTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testNopTransformer() { assertNotNull(TransformerUtils.nullTransformer()); assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer()); assertEquals(null, TransformerUtils.nopTransformer().transform(null)); assertEquals(cObject, TransformerUtils.nopTransformer().transform(cObject)); assertEquals(cString, TransformerUtils.nopTransformer().transform(cString)); assertEquals(cInteger, TransformerUtils.nopTransformer().transform(cInteger)); }
public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); } }
TransformerUtils { public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testConstantTransformer() { assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(null)); assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cObject)); assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cString)); assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cInteger)); assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.constantTransformer(null)); }
public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) { return ConstantTransformer.constantTransformer(constantToReturn); }
TransformerUtils { public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) { return ConstantTransformer.constantTransformer(constantToReturn); } }
TransformerUtils { public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) { return ConstantTransformer.constantTransformer(constantToReturn); } private TransformerUtils(); }
TransformerUtils { public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) { return ConstantTransformer.constantTransformer(constantToReturn); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) { return ConstantTransformer.constantTransformer(constantToReturn); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testGet() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; cache.set(key, value, seconds); assertThat((String) cache.get(key), equalTo(value)); t.addSeconds(seconds + 1); assertThat(cache.get(key), nullValue()); }
public Object get(String key) { return get(key, null); }
LocalCacheHandler extends SimpleCacheHandler { public Object get(String key) { return get(key, null); } }
LocalCacheHandler extends SimpleCacheHandler { public Object get(String key) { return get(key, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); }
LocalCacheHandler extends SimpleCacheHandler { public Object get(String key) { return get(key, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
LocalCacheHandler extends SimpleCacheHandler { public Object get(String key) { return get(key, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
@Test public void testCloneTransformer() { assertEquals(null, TransformerUtils.cloneTransformer().transform(null)); assertEquals(cString, TransformerUtils.cloneTransformer().transform(cString)); assertEquals(cInteger, TransformerUtils.cloneTransformer().transform(cInteger)); try { assertEquals(cObject, TransformerUtils.cloneTransformer().transform(cObject)); } catch (final IllegalArgumentException ex) { return; } fail(); }
public static <T> Transformer<T, T> cloneTransformer() { return CloneTransformer.cloneTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> cloneTransformer() { return CloneTransformer.cloneTransformer(); } }
TransformerUtils { public static <T> Transformer<T, T> cloneTransformer() { return CloneTransformer.cloneTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> cloneTransformer() { return CloneTransformer.cloneTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> cloneTransformer() { return CloneTransformer.cloneTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test @SuppressWarnings("boxing") public void testMapTransformer() { final Map<Object, Integer> map = new HashMap<Object, Integer>(); map.put(null, 0); map.put(cObject, 1); map.put(cString, 2); assertEquals(Integer.valueOf(0), TransformerUtils.mapTransformer(map).transform(null)); assertEquals(Integer.valueOf(1), TransformerUtils.mapTransformer(map).transform(cObject)); assertEquals(Integer.valueOf(2), TransformerUtils.mapTransformer(map).transform(cString)); assertEquals(null, TransformerUtils.mapTransformer(map).transform(cInteger)); assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.mapTransformer(null)); }
public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) { return MapTransformer.mapTransformer(map); }
TransformerUtils { public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) { return MapTransformer.mapTransformer(map); } }
TransformerUtils { public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) { return MapTransformer.mapTransformer(map); } private TransformerUtils(); }
TransformerUtils { public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) { return MapTransformer.mapTransformer(map); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) { return MapTransformer.mapTransformer(map); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testExecutorTransformer() { assertEquals(null, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(null)); assertEquals(cObject, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cObject)); assertEquals(cString, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cString)); assertEquals(cInteger, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cInteger)); try { TransformerUtils.asTransformer((Closure<Object>) null); } catch (final NullPointerException ex) { return; } fail(); }
public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testPredicateTransformer() { assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(TruePredicate.truePredicate()).transform(null)); assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(TruePredicate.truePredicate()).transform(cObject)); assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(TruePredicate.truePredicate()).transform(cString)); assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(TruePredicate.truePredicate()).transform(cInteger)); try { TransformerUtils.asTransformer((Predicate<Object>) null); } catch (final IllegalArgumentException ex) { return; } fail(); }
public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testFactoryTransformer() { assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(null)); assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cObject)); assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cString)); assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cInteger)); try { TransformerUtils.asTransformer((Factory<Object>) null); } catch (final NullPointerException ex) { return; } fail(); }
public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test @SuppressWarnings("unchecked") public void testChainedTransformer() { final Transformer<Object, Object> a = TransformerUtils.<Object, Object>constantTransformer("A"); final Transformer<Object, Object> b = TransformerUtils.constantTransformer((Object) "B"); assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null)); assertEquals("B", TransformerUtils.chainedTransformer(a, b).transform(null)); assertEquals("A", TransformerUtils.chainedTransformer(new Transformer[] { b, a }).transform(null)); Collection<Transformer<Object, Object>> coll = new ArrayList<Transformer<Object, Object>>(); coll.add(b); coll.add(a); assertEquals("A", TransformerUtils.chainedTransformer(coll).transform(null)); assertSame(NOPTransformer.INSTANCE, TransformerUtils.chainedTransformer(new Transformer[0])); assertSame(NOPTransformer.INSTANCE, TransformerUtils.chainedTransformer(Collections.<Transformer<Object, Object>>emptyList())); try { TransformerUtils.chainedTransformer(null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.chainedTransformer((Transformer[]) null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.chainedTransformer((Collection<Transformer<Object, Object>>) null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.chainedTransformer(new Transformer[] {null, null}); fail(); } catch (final NullPointerException ex) {} try { coll = new ArrayList<Transformer<Object, Object>>(); coll.add(null); coll.add(null); TransformerUtils.chainedTransformer(coll); fail(); } catch (final NullPointerException ex) {} }
public static <T> Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers) { return ChainedTransformer.chainedTransformer(transformers); }
TransformerUtils { public static <T> Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers) { return ChainedTransformer.chainedTransformer(transformers); } }
TransformerUtils { public static <T> Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers) { return ChainedTransformer.chainedTransformer(transformers); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers) { return ChainedTransformer.chainedTransformer(transformers); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers) { return ChainedTransformer.chainedTransformer(transformers); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testIfTransformer() { final Transformer<Object, String> a = TransformerUtils.constantTransformer("A"); final Transformer<Object, String> b = TransformerUtils.constantTransformer("B"); final Transformer<Object, String> c = TransformerUtils.constantTransformer("C"); assertEquals("A", TransformerUtils.ifTransformer(TruePredicate.truePredicate(), a, b).transform(null)); assertEquals("B", TransformerUtils.ifTransformer(FalsePredicate.falsePredicate(), a, b).transform(null)); Predicate<Integer> lessThanFivePredicate = new Predicate<Integer>() { @Override public boolean evaluate(Integer value) { return value < 5; } }; assertEquals("A", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(1)); assertEquals("B", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(5)); Predicate<String> equalsAPredicate = EqualPredicate.equalPredicate("A"); assertEquals("C", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("A")); assertEquals("B", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("B")); try { TransformerUtils.ifTransformer(null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.ifTransformer(TruePredicate.truePredicate(), null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.ifTransformer(null, ConstantTransformer.constantTransformer("A")); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.ifTransformer(null, null, null); fail(); } catch (final NullPointerException ex) {} }
public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test @SuppressWarnings("unchecked") public void testSwitchTransformer() { final Transformer<String, String> a = TransformerUtils.constantTransformer("A"); final Transformer<String, String> b = TransformerUtils.constantTransformer("B"); final Transformer<String, String> c = TransformerUtils.constantTransformer("C"); assertEquals("A", TransformerUtils.switchTransformer(TruePredicate.truePredicate(), a, b).transform(null)); assertEquals("B", TransformerUtils.switchTransformer(FalsePredicate.falsePredicate(), a, b).transform(null)); assertEquals(null, TransformerUtils.<Object, String>switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }).transform("WELL")); assertEquals("A", TransformerUtils.switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }).transform("HELLO")); assertEquals("B", TransformerUtils.switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }).transform("THERE")); assertEquals("C", TransformerUtils.switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }, c).transform("WELL")); Map<Predicate<String>, Transformer<String, String>> map = new HashMap<Predicate<String>, Transformer<String,String>>(); map.put(EqualPredicate.equalPredicate("HELLO"), a); map.put(EqualPredicate.equalPredicate("THERE"), b); assertEquals(null, TransformerUtils.switchTransformer(map).transform("WELL")); assertEquals("A", TransformerUtils.switchTransformer(map).transform("HELLO")); assertEquals("B", TransformerUtils.switchTransformer(map).transform("THERE")); map.put(null, c); assertEquals("C", TransformerUtils.switchTransformer(map).transform("WELL")); assertEquals(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchTransformer(new Predicate[0], new Transformer[0])); assertEquals(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchTransformer(new HashMap<Predicate<Object>, Transformer<Object, Object>>())); map = new HashMap<Predicate<String>, Transformer<String, String>>(); map.put(null, null); assertEquals(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchTransformer(map)); try { TransformerUtils.switchTransformer(null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer((Predicate[]) null, (Transformer[]) null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer((Map<Predicate<Object>, Transformer<Object, Object>>) null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer(new Predicate[2], new Transformer[2]); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer( new Predicate[] { TruePredicate.truePredicate() }, new Transformer[] { a, b }); fail(); } catch (final IllegalArgumentException ex) {} }
@SuppressWarnings("unchecked") @Deprecated public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer) { return SwitchTransformer.switchTransformer(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer); }
TransformerUtils { @SuppressWarnings("unchecked") @Deprecated public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer) { return SwitchTransformer.switchTransformer(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer); } }
TransformerUtils { @SuppressWarnings("unchecked") @Deprecated public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer) { return SwitchTransformer.switchTransformer(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer); } private TransformerUtils(); }
TransformerUtils { @SuppressWarnings("unchecked") @Deprecated public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer) { return SwitchTransformer.switchTransformer(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { @SuppressWarnings("unchecked") @Deprecated public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer) { return SwitchTransformer.switchTransformer(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testSwitchMapTransformer() { final Transformer<String, String> a = TransformerUtils.constantTransformer("A"); final Transformer<String, String> b = TransformerUtils.constantTransformer("B"); final Transformer<String, String> c = TransformerUtils.constantTransformer("C"); Map<String, Transformer<String, String>> map = new HashMap<String, Transformer<String,String>>(); map.put("HELLO", a); map.put("THERE", b); assertEquals(null, TransformerUtils.switchMapTransformer(map).transform("WELL")); assertEquals("A", TransformerUtils.switchMapTransformer(map).transform("HELLO")); assertEquals("B", TransformerUtils.switchMapTransformer(map).transform("THERE")); map.put(null, c); assertEquals("C", TransformerUtils.switchMapTransformer(map).transform("WELL")); assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchMapTransformer(new HashMap<Object, Transformer<Object, Object>>())); map = new HashMap<String, Transformer<String, String>>(); map.put(null, null); assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchMapTransformer(map)); try { TransformerUtils.switchMapTransformer(null); fail(); } catch (final NullPointerException ex) {} }
@SuppressWarnings("unchecked") public static <I, O> Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers) { if (objectsAndTransformers == null) { throw new NullPointerException("The object and transformer map must not be null"); } final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null); final int size = objectsAndTransformers.size(); final Transformer<? super I, ? extends O>[] trs = new Transformer[size]; final Predicate<I>[] preds = new Predicate[size]; int i = 0; for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) { preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey()); trs[i++] = entry.getValue(); } return TransformerUtils.switchTransformer(preds, trs, def); }
TransformerUtils { @SuppressWarnings("unchecked") public static <I, O> Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers) { if (objectsAndTransformers == null) { throw new NullPointerException("The object and transformer map must not be null"); } final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null); final int size = objectsAndTransformers.size(); final Transformer<? super I, ? extends O>[] trs = new Transformer[size]; final Predicate<I>[] preds = new Predicate[size]; int i = 0; for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) { preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey()); trs[i++] = entry.getValue(); } return TransformerUtils.switchTransformer(preds, trs, def); } }
TransformerUtils { @SuppressWarnings("unchecked") public static <I, O> Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers) { if (objectsAndTransformers == null) { throw new NullPointerException("The object and transformer map must not be null"); } final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null); final int size = objectsAndTransformers.size(); final Transformer<? super I, ? extends O>[] trs = new Transformer[size]; final Predicate<I>[] preds = new Predicate[size]; int i = 0; for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) { preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey()); trs[i++] = entry.getValue(); } return TransformerUtils.switchTransformer(preds, trs, def); } private TransformerUtils(); }
TransformerUtils { @SuppressWarnings("unchecked") public static <I, O> Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers) { if (objectsAndTransformers == null) { throw new NullPointerException("The object and transformer map must not be null"); } final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null); final int size = objectsAndTransformers.size(); final Transformer<? super I, ? extends O>[] trs = new Transformer[size]; final Predicate<I>[] preds = new Predicate[size]; int i = 0; for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) { preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey()); trs[i++] = entry.getValue(); } return TransformerUtils.switchTransformer(preds, trs, def); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { @SuppressWarnings("unchecked") public static <I, O> Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers) { if (objectsAndTransformers == null) { throw new NullPointerException("The object and transformer map must not be null"); } final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null); final int size = objectsAndTransformers.size(); final Transformer<? super I, ? extends O>[] trs = new Transformer[size]; final Predicate<I>[] preds = new Predicate[size]; int i = 0; for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) { preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey()); trs[i++] = entry.getValue(); } return TransformerUtils.switchTransformer(preds, trs, def); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testInvokerTransformer() { final List<Object> list = new ArrayList<Object>(); assertEquals(Integer.valueOf(0), TransformerUtils.invokerTransformer("size").transform(list)); list.add(new Object()); assertEquals(Integer.valueOf(1), TransformerUtils.invokerTransformer("size").transform(list)); assertEquals(null, TransformerUtils.invokerTransformer("size").transform(null)); try { TransformerUtils.invokerTransformer(null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.invokerTransformer("noSuchMethod").transform(new Object()); fail(); } catch (final FunctorException ex) {} }
public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testGetBulk() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; int seconds2 = 200; String key2 = "key2"; String value2 = "value2"; cache.set(key, value, seconds); cache.set(key2, value2, seconds2); Set<String> keys = Sets.newHashSet(key, key2); Map<String, Object> map = cache.getBulk(keys); assertThat(map.size(), equalTo(2)); assertThat((String) map.get(key), equalTo(value)); assertThat((String) map.get(key2), equalTo(value2)); t.addSeconds(seconds + 1); map = cache.getBulk(keys); assertThat(map.size(), equalTo(1)); assertThat((String) map.get(key2), equalTo(value2)); t.reset(); t.addSeconds(seconds2 + 1); map = cache.getBulk(keys); assertThat(map.size(), equalTo(0)); }
public Map<String, Object> getBulk(Set<String> keys) { return getBulk(keys, null); }
LocalCacheHandler extends SimpleCacheHandler { public Map<String, Object> getBulk(Set<String> keys) { return getBulk(keys, null); } }
LocalCacheHandler extends SimpleCacheHandler { public Map<String, Object> getBulk(Set<String> keys) { return getBulk(keys, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); }
LocalCacheHandler extends SimpleCacheHandler { public Map<String, Object> getBulk(Set<String> keys) { return getBulk(keys, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
LocalCacheHandler extends SimpleCacheHandler { public Map<String, Object> getBulk(Set<String> keys) { return getBulk(keys, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
@Test public void testInvokerTransformer2() { final List<Object> list = new ArrayList<Object>(); assertEquals(Boolean.FALSE, TransformerUtils.invokerTransformer("contains", new Class[] { Object.class }, new Object[] { cString }).transform(list)); list.add(cString); assertEquals(Boolean.TRUE, TransformerUtils.invokerTransformer("contains", new Class[] { Object.class }, new Object[] { cString }).transform(list)); assertEquals(null, TransformerUtils.invokerTransformer("contains", new Class[] { Object.class }, new Object[] { cString }).transform(null)); try { TransformerUtils.invokerTransformer(null, null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.invokerTransformer("noSuchMethod", new Class[] { Object.class }, new Object[] { cString }).transform(new Object()); fail(); } catch (final FunctorException ex) {} try { TransformerUtils.invokerTransformer("badArgs", null, new Object[] { cString }); fail(); } catch (final IllegalArgumentException ex) {} try { TransformerUtils.invokerTransformer("badArgs", new Class[] { Object.class }, null); fail(); } catch (final IllegalArgumentException ex) {} try { TransformerUtils.invokerTransformer("badArgs", new Class[] {}, new Object[] { cString }); fail(); } catch (final IllegalArgumentException ex) {} }
public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testStringValueTransformer() { assertNotNull( "StringValueTransformer should NEVER return a null value.", TransformerUtils.stringValueTransformer().transform(null)); assertEquals( "StringValueTransformer should return \"null\" when given a null argument.", "null", TransformerUtils.stringValueTransformer().transform(null)); assertEquals( "StringValueTransformer should return toString value", "6", TransformerUtils.stringValueTransformer().transform(Integer.valueOf(6))); }
public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testInstantiateTransformerNull() { try { TransformerUtils.instantiateTransformer(null, new Object[] { "str" }); fail(); } catch (final IllegalArgumentException ex) {} try { TransformerUtils.instantiateTransformer(new Class[] {}, new Object[] { "str" }); fail(); } catch (final IllegalArgumentException ex) {} Transformer<Class<?>, Object> trans = TransformerUtils.instantiateTransformer(new Class[] { Long.class }, new Object[] { null }); try { trans.transform(String.class); fail(); } catch (final FunctorException ex) {} trans = TransformerUtils.instantiateTransformer(); assertEquals("", trans.transform(String.class)); trans = TransformerUtils.instantiateTransformer(new Class[] { Long.TYPE }, new Object[] { new Long(1000L) }); assertEquals(new Date(1000L), trans.transform(Date.class)); }
public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); }
TransformerUtils { public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); } }
TransformerUtils { public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testSingletonPatternInSerialization() { final Object[] singletones = new Object[] { ExceptionTransformer.INSTANCE, NOPTransformer.INSTANCE, StringValueTransformer.stringValueTransformer(), }; for (final Object original : singletones) { TestUtils.assertSameAfterSerialization("Singleton pattern broken for " + original.getClass(), original); } }
public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates, final Transformer<? super I, ? extends O>[] transformers, final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer( final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer( final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Transformer<T, String> stringValueTransformer(); }
@Test public void testExceptionPredicate() { assertNotNull(PredicateUtils.exceptionPredicate()); assertSame(PredicateUtils.exceptionPredicate(), PredicateUtils.exceptionPredicate()); try { PredicateUtils.exceptionPredicate().evaluate(null); } catch (final FunctorException ex) { try { PredicateUtils.exceptionPredicate().evaluate(cString); } catch (final FunctorException ex2) { return; } } fail(); }
public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); }
PredicateUtils { public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); } }
PredicateUtils { public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testIsNotNullPredicate() { assertNotNull(PredicateUtils.notNullPredicate()); assertSame(PredicateUtils.notNullPredicate(), PredicateUtils.notNullPredicate()); assertEquals(false, PredicateUtils.notNullPredicate().evaluate(null)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cObject)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cString)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cInteger)); }
public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); }
PredicateUtils { public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); } }
PredicateUtils { public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testIdentityPredicate() { assertSame(nullPredicate(), PredicateUtils.identityPredicate(null)); assertNotNull(PredicateUtils.identityPredicate(Integer.valueOf(6))); assertEquals(false, PredicateUtils.identityPredicate(Integer.valueOf(6)).evaluate(null)); assertEquals(false, PredicateUtils.<Object>identityPredicate(Integer.valueOf(6)).evaluate(cObject)); assertEquals(false, PredicateUtils.<Object>identityPredicate(Integer.valueOf(6)).evaluate(cString)); assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(cInteger)); assertEquals(true, PredicateUtils.identityPredicate(cInteger).evaluate(cInteger)); }
public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); }
PredicateUtils { public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); } }
PredicateUtils { public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testTruePredicate() { assertNotNull(TruePredicate.truePredicate()); assertSame(TruePredicate.truePredicate(), TruePredicate.truePredicate()); assertEquals(true, TruePredicate.truePredicate().evaluate(null)); assertEquals(true, TruePredicate.truePredicate().evaluate(cObject)); assertEquals(true, TruePredicate.truePredicate().evaluate(cString)); assertEquals(true, TruePredicate.truePredicate().evaluate(cInteger)); }
public static <T> Predicate<T> truePredicate() { return TruePredicate.truePredicate(); }
PredicateUtils { public static <T> Predicate<T> truePredicate() { return TruePredicate.truePredicate(); } }
PredicateUtils { public static <T> Predicate<T> truePredicate() { return TruePredicate.truePredicate(); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> truePredicate() { return TruePredicate.truePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> truePredicate() { return TruePredicate.truePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testFalsePredicate() { assertNotNull(FalsePredicate.falsePredicate()); assertSame(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()); assertEquals(false, FalsePredicate.falsePredicate().evaluate(null)); assertEquals(false, FalsePredicate.falsePredicate().evaluate(cObject)); assertEquals(false, FalsePredicate.falsePredicate().evaluate(cString)); assertEquals(false, FalsePredicate.falsePredicate().evaluate(cInteger)); }
public static <T> Predicate<T> falsePredicate() { return FalsePredicate.falsePredicate(); }
PredicateUtils { public static <T> Predicate<T> falsePredicate() { return FalsePredicate.falsePredicate(); } }
PredicateUtils { public static <T> Predicate<T> falsePredicate() { return FalsePredicate.falsePredicate(); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> falsePredicate() { return FalsePredicate.falsePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> falsePredicate() { return FalsePredicate.falsePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testNotPredicate() { assertNotNull(PredicateUtils.notPredicate(TruePredicate.truePredicate())); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cObject)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cString)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cInteger)); }
public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testDelete() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; cache.set(key, value, seconds); assertThat((String) cache.get(key), equalTo(value)); cache.delete(key); assertThat(cache.get(key), nullValue()); }
@Override public void delete(String key) { cache.remove(key); }
LocalCacheHandler extends SimpleCacheHandler { @Override public void delete(String key) { cache.remove(key); } }
LocalCacheHandler extends SimpleCacheHandler { @Override public void delete(String key) { cache.remove(key); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); }
LocalCacheHandler extends SimpleCacheHandler { @Override public void delete(String key) { cache.remove(key); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
LocalCacheHandler extends SimpleCacheHandler { @Override public void delete(String key) { cache.remove(key); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
@Test(expected=NullPointerException.class) public void testNotPredicateEx() { PredicateUtils.notPredicate(null); }
public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testAndPredicate() { assertEquals(true, PredicateUtils.andPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); }
public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test(expected=NullPointerException.class) public void testAndPredicateEx() { PredicateUtils.andPredicate(null, null); }
public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@SuppressWarnings("unchecked") @Test public void testAllPredicate() { assertTrue(AllPredicate.allPredicate(new Predicate[] {}), null); assertEquals(true, AllPredicate.allPredicate(new Predicate[] { TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, AllPredicate.allPredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, AllPredicate.allPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, AllPredicate.allPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(TruePredicate.truePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); assertFalse(AllPredicate.allPredicate(coll), null); coll.clear(); coll.add(TruePredicate.truePredicate()); assertTrue(AllPredicate.allPredicate(coll), null); coll.clear(); assertTrue(AllPredicate.allPredicate(coll), null); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test(expected=NullPointerException.class) public void testAllPredicateEx1() { AllPredicate.allPredicate((Predicate<Object>[]) null); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAllPredicateEx2() { AllPredicate.<Object>allPredicate(new Predicate[] { null }); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAllPredicateEx3() { AllPredicate.allPredicate(new Predicate[] { null, null }); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test(expected=NullPointerException.class) public void testAllPredicateEx4() { AllPredicate.allPredicate((Collection<Predicate<Object>>) null); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testAllPredicateEx5() { AllPredicate.allPredicate(Collections.<Predicate<Object>>emptyList()); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test(expected=NullPointerException.class) public void testAllPredicateEx6() { final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(null); coll.add(null); AllPredicate.allPredicate(coll); }
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test public void testAdd() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; int seconds2 = 200; String key2 = "key2"; String value2 = "value2"; cache.set(key, value, seconds); cache.add(key, value2, seconds); cache.add(key2, value2, seconds2); assertThat((String) cache.get(key), equalTo(value)); assertThat((String) cache.get(key2), equalTo(value2)); }
@Override public void add(String key, Object value, int exptimeSeconds) { long now = ticker.read(); Entry entry = new Entry(value, now + TimeUnit.SECONDS.toNanos(exptimeSeconds)); cache.putIfAbsent(key, entry); }
LocalCacheHandler extends SimpleCacheHandler { @Override public void add(String key, Object value, int exptimeSeconds) { long now = ticker.read(); Entry entry = new Entry(value, now + TimeUnit.SECONDS.toNanos(exptimeSeconds)); cache.putIfAbsent(key, entry); } }
LocalCacheHandler extends SimpleCacheHandler { @Override public void add(String key, Object value, int exptimeSeconds) { long now = ticker.read(); Entry entry = new Entry(value, now + TimeUnit.SECONDS.toNanos(exptimeSeconds)); cache.putIfAbsent(key, entry); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); }
LocalCacheHandler extends SimpleCacheHandler { @Override public void add(String key, Object value, int exptimeSeconds) { long now = ticker.read(); Entry entry = new Entry(value, now + TimeUnit.SECONDS.toNanos(exptimeSeconds)); cache.putIfAbsent(key, entry); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
LocalCacheHandler extends SimpleCacheHandler { @Override public void add(String key, Object value, int exptimeSeconds) { long now = ticker.read(); Entry entry = new Entry(value, now + TimeUnit.SECONDS.toNanos(exptimeSeconds)); cache.putIfAbsent(key, entry); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
@Test public void testOrPredicate() { assertEquals(true, PredicateUtils.orPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.orPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); }
public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test(expected=NullPointerException.class) public void testOrPredicateEx() { PredicateUtils.orPredicate(null, null); }
public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@SuppressWarnings("unchecked") @Test public void testAnyPredicate() { assertFalse(PredicateUtils.anyPredicate(new Predicate[] {}), null); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.anyPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(TruePredicate.truePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); assertEquals(false, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); assertFalse(PredicateUtils.anyPredicate(coll), null); coll.clear(); coll.add(TruePredicate.truePredicate()); assertTrue(PredicateUtils.anyPredicate(coll), null); coll.clear(); assertFalse(PredicateUtils.anyPredicate(coll), null); }
public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@Test(expected=NullPointerException.class) public void testAnyPredicateEx1() { PredicateUtils.anyPredicate((Predicate<Object>[]) null); }
public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAnyPredicateEx2() { PredicateUtils.anyPredicate(new Predicate[] {null}); }
public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }