@Test public void containsWithEquator() { final List<String> base = new ArrayList<String>(); base.add("AC"); base.add("BB"); base.add("CA"); final Equator<String> secondLetterEquator = new Equator<String>() { @Override public boolean equate(String o1, String o2) { return o1.charAt(1) == o2.charAt(1); } @Override public int hash(String o) { return o.charAt(1); } }; assertFalse(base.contains("CC")); assertTrue(IterableUtils.contains(base, "AC", secondLetterEquator)); assertTrue(IterableUtils.contains(base, "CC", secondLetterEquator)); assertFalse(IterableUtils.contains(base, "CX", secondLetterEquator)); assertFalse(IterableUtils.contains(null, null, secondLetterEquator)); try { IterableUtils.contains(base, "AC", null); fail("expecting NullPointerException"); } catch (final NullPointerException npe) { } }
public static <E> boolean contains(final Iterable<E> iterable, final Object object) { if (iterable instanceof Collection<?>) { return ((Collection<E>) iterable).contains(object); } else { return IteratorUtils.contains(emptyIteratorIfNull(iterable), object); } }
IterableUtils { public static <E> boolean contains(final Iterable<E> iterable, final Object object) { if (iterable instanceof Collection<?>) { return ((Collection<E>) iterable).contains(object); } else { return IteratorUtils.contains(emptyIteratorIfNull(iterable), object); } } }
IterableUtils { public static <E> boolean contains(final Iterable<E> iterable, final Object object) { if (iterable instanceof Collection<?>) { return ((Collection<E>) iterable).contains(object); } else { return IteratorUtils.contains(emptyIteratorIfNull(iterable), object); } }  }
IterableUtils { public static <E> boolean contains(final Iterable<E> iterable, final Object object) { if (iterable instanceof Collection<?>) { return ((Collection<E>) iterable).contains(object); } else { return IteratorUtils.contains(emptyIteratorIfNull(iterable), object); } }  @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Iterable<E> emptyIterable(); @SuppressWarnings("unchecked") static Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b); @SuppressWarnings("unchecked") static Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b,
                                                  final Iterable<? extends E> c); @SuppressWarnings("unchecked") static Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b,
                                                  final Iterable<? extends E> c,
                                                  final Iterable<? extends E> d); static Iterable<E> chainedIterable(final Iterable<? extends E>... iterables); static Iterable<E> collatedIterable(final Iterable<? extends E> a,
                                                   final Iterable<? extends E> b); static Iterable<E> collatedIterable(final Comparator<? super E> comparator,
                                                   final Iterable<? extends E> a,
                                                   final Iterable<? extends E> b); static Iterable<E> filteredIterable(final Iterable<E> iterable,
                                                   final Predicate<? super E> predicate); static Iterable<E> boundedIterable(final Iterable<E> iterable, final long maxSize); static Iterable<E> loopingIterable(final Iterable<E> iterable); static Iterable<E> reversedIterable(final Iterable<E> iterable); static Iterable<E> skippingIterable(final Iterable<E> iterable, final long elementsToSkip); static Iterable<O> transformedIterable(final Iterable<I> iterable,
                                                         final Transformer<? super I, ? extends O> transformer); static Iterable<E> uniqueIterable(final Iterable<E> iterable); static Iterable<E> unmodifiableIterable(final Iterable<E> iterable); static Iterable<E> zippingIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b); static Iterable<E> zippingIterable(final Iterable<? extends E> first,
                                                  final Iterable<? extends E>... others); static Iterable<E> emptyIfNull(final Iterable<E> iterable); static void forEach(final Iterable<E> iterable, final Closure<? super E> closure); static E forEachButLast(final Iterable<E> iterable, final Closure<? super E> closure); static E find(final Iterable<E> iterable, final Predicate<? super E> predicate); static int indexOf(final Iterable<E> iterable, final Predicate<? super E> predicate); static boolean matchesAll(final Iterable<E> iterable, final Predicate<? super E> predicate); static boolean matchesAny(final Iterable<E> iterable, final Predicate<? super E> predicate); static long countMatches(final Iterable<E> input, final Predicate<? super E> predicate); static boolean isEmpty(final Iterable<?> iterable); static boolean contains(final Iterable<E> iterable, final Object object); static boolean contains(final Iterable<? extends E> iterable, final E object,
                                       final Equator<? super E> equator); static int frequency(final Iterable<E> iterable, final T obj); static T get(final Iterable<T> iterable, final int index); static int size(final Iterable<?> iterable); static List<List<O>> partition(final Iterable<? extends O> iterable,
                                              final Predicate<? super O> predicate); static List<List<O>> partition(final Iterable<? extends O> iterable,
                                              final Predicate<? super O>... predicates); static List<R> partition(final Iterable<? extends O> iterable,
            final Factory<R> partitionFactory, final Predicate<? super O>... predicates); static List<E> toList(final Iterable<E> iterable); static String toString(final Iterable<E> iterable); static String toString(final Iterable<E> iterable,
                                      final Transformer<? super E, String> transformer); static String toString(final Iterable<E> iterable,
                                      final Transformer<? super E, String> transformer,
                                      final String delimiter,
                                      final String prefix,
                                      final String suffix); }
IterableUtils { public static <E> boolean contains(final Iterable<E> iterable, final Object object) { if (iterable instanceof Collection<?>) { return ((Collection<E>) iterable).contains(object); } else { return IteratorUtils.contains(emptyIteratorIfNull(iterable), object); } }  @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Iterable<E> emptyIterable(); @SuppressWarnings("unchecked") static Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b); @SuppressWarnings("unchecked") static Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b,
                                                  final Iterable<? extends E> c); @SuppressWarnings("unchecked") static Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b,
                                                  final Iterable<? extends E> c,
                                                  final Iterable<? extends E> d); static Iterable<E> chainedIterable(final Iterable<? extends E>... iterables); static Iterable<E> collatedIterable(final Iterable<? extends E> a,
                                                   final Iterable<? extends E> b); static Iterable<E> collatedIterable(final Comparator<? super E> comparator,
                                                   final Iterable<? extends E> a,
                                                   final Iterable<? extends E> b); static Iterable<E> filteredIterable(final Iterable<E> iterable,
                                                   final Predicate<? super E> predicate); static Iterable<E> boundedIterable(final Iterable<E> iterable, final long maxSize); static Iterable<E> loopingIterable(final Iterable<E> iterable); static Iterable<E> reversedIterable(final Iterable<E> iterable); static Iterable<E> skippingIterable(final Iterable<E> iterable, final long elementsToSkip); static Iterable<O> transformedIterable(final Iterable<I> iterable,
                                                         final Transformer<? super I, ? extends O> transformer); static Iterable<E> uniqueIterable(final Iterable<E> iterable); static Iterable<E> unmodifiableIterable(final Iterable<E> iterable); static Iterable<E> zippingIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b); static Iterable<E> zippingIterable(final Iterable<? extends E> first,
                                                  final Iterable<? extends E>... others); static Iterable<E> emptyIfNull(final Iterable<E> iterable); static void forEach(final Iterable<E> iterable, final Closure<? super E> closure); static E forEachButLast(final Iterable<E> iterable, final Closure<? super E> closure); static E find(final Iterable<E> iterable, final Predicate<? super E> predicate); static int indexOf(final Iterable<E> iterable, final Predicate<? super E> predicate); static boolean matchesAll(final Iterable<E> iterable, final Predicate<? super E> predicate); static boolean matchesAny(final Iterable<E> iterable, final Predicate<? super E> predicate); static long countMatches(final Iterable<E> input, final Predicate<? super E> predicate); static boolean isEmpty(final Iterable<?> iterable); static boolean contains(final Iterable<E> iterable, final Object object); static boolean contains(final Iterable<? extends E> iterable, final E object,
                                       final Equator<? super E> equator); static int frequency(final Iterable<E> iterable, final T obj); static T get(final Iterable<T> iterable, final int index); static int size(final Iterable<?> iterable); static List<List<O>> partition(final Iterable<? extends O> iterable,
                                              final Predicate<? super O> predicate); static List<List<O>> partition(final Iterable<? extends O> iterable,
                                              final Predicate<? super O>... predicates); static List<R> partition(final Iterable<? extends O> iterable,
            final Factory<R> partitionFactory, final Predicate<? super O>... predicates); static List<E> toList(final Iterable<E> iterable); static String toString(final Iterable<E> iterable); static String toString(final Iterable<E> iterable,
                                      final Transformer<? super E, String> transformer); static String toString(final Iterable<E> iterable,
                                      final Transformer<? super E, String> transformer,
                                      final String delimiter,
                                      final String prefix,
                                      final String suffix);  }