@Test public void testTakeBetween() { List list = asList(2, 4, 5, 6, 8); assertEquals(asList(2, 4), ListUtil.takeWhile(list, (Integer n) -> (n % 2 == 0))); assertEquals(asList(), ListUtil.takeWhile(list, (Integer n) -> n < 0)); assertEquals(list, ListUtil.takeWhile(list, (Integer n) -> n > 0)); assertNull(ListUtil.takeWhile(null, (Integer n) -> n > 0)); assertEquals(asList(6, 8), ListUtil.dropWhile(list, (Integer n) -> n <= 5)); assertEquals(asList(), ListUtil.dropWhile(list, (Integer n) -> n <= 8)); assertEquals(list, ListUtil.dropWhile(list, (Integer n) -> n < 2)); assertEquals(asList(5, 6), ListUtil.takeBetween(list, (Integer n) -> (n % 2 == 0), (Integer n) -> n < 8)); }
public static <V, S extends Collection<? extends V>, D extends Collection<? super V>> D takeBetween( S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest) { if (source != null) { boolean startTaking = false; for (V s : source) { if (!startTaking && dropPred.test(s)) continue; startTaking = true; if (!whilePred.test(s)) break; dest.add(s); } } return dest; }
ListUtil { public static <V, S extends Collection<? extends V>, D extends Collection<? super V>> D takeBetween( S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest) { if (source != null) { boolean startTaking = false; for (V s : source) { if (!startTaking && dropPred.test(s)) continue; startTaking = true; if (!whilePred.test(s)) break; dest.add(s); } } return dest; } }
ListUtil { public static <V, S extends Collection<? extends V>, D extends Collection<? super V>> D takeBetween( S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest) { if (source != null) { boolean startTaking = false; for (V s : source) { if (!startTaking && dropPred.test(s)) continue; startTaking = true; if (!whilePred.test(s)) break; dest.add(s); } } return dest; }  }
ListUtil { public static <V, S extends Collection<? extends V>, D extends Collection<? super V>> D takeBetween( S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest) { if (source != null) { boolean startTaking = false; for (V s : source) { if (!startTaking && dropPred.test(s)) continue; startTaking = true; if (!whilePred.test(s)) break; dest.add(s); } } return dest; }  static C map(
      Collection<? extends TSrc> source, BiFunction<? super TSrc, Integer, ? extends TDest> func, C dest); static C map(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends TDest> func, C dest); static List<TDest> map(
      Collection<? extends TSrc> source, BiFunction<? super TSrc, Integer, ? extends TDest> func); static List<TDest> map(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends TDest> func); static C flatMap(Collection<? extends TSrc> source,
      BiFunction<? super TSrc, Integer, ? extends Collection< ? extends TDest>> func, C dest); static C flatMap(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends Collection< ? extends TDest>> func, C dest); static List<TDest> flatMap(Collection<? extends TSrc> source,
      BiFunction<? super TSrc, Integer, ? extends Collection< ? extends TDest>> func); static List<TDest> flatMap(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends Collection< ? extends TDest>> func); static Set<TDest> unique(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends TDest> func); static List<TId> getIds(Collection<? extends Identifiable<TId>> identifiables); static Map<K, List<E>> groupBy(
      Collection<? extends E> source, Function<? super E, ? extends K> classifier); static Map<TK, TV> map(Map<? extends K, ? extends V> source,
      Function<? super K, ? extends TK> keyFunc, Function<? super V, ? extends TV> valFunc); static Map<K, TV> mapValues(
      Map<? extends K, ? extends V> source, Function<? super V, ? extends TV> valFunc); static Map<TK, V> mapKeys(
      Map<? extends K, ? extends V> source, Function<? super K, ? extends TK> keyFunc); static long[] toLongArray(Collection<Object> list); static Map<K, V> toMap(Collection<V> source, Function<? super V, ? extends K> keyFunc); static Map<K, V> toMap(
      Collection<S> source, Function<? super S, ? extends K> keyFunc, Function<? super S, ? extends V> valFunc); static D filter(
      S source, Predicate<? super V> pred, D dest); static List<V> filter(C source, Predicate<? super V> pred); static List<V> orderBy(
      C source, final Function<? super V, ? extends Comparable> by); static List<V> orderBy(
      C src, final Function<? super V, K> by, final boolean desc); static boolean contains(long[] longs, long match); static String join(T[] list, String delimiter); static String join(Collection<T> list, String delimiter); static boolean exists(C source, Predicate<? super V> pred); static V first(C source, Predicate<? super V> pred); static int indexOf(C source, Predicate<? super V> pred); static D takeBetween(
      S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest); static List<V> takeBetween(
      S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred); static D takeWhile(
      S source, Predicate<? super V> pred, D dest); static List<V> takeWhile(S source, Predicate<? super V> pred); static D dropWhile(
      S source, Predicate<? super V> pred, D dest); static List<V> dropWhile(S source, Predicate<? super V> pred); static T last(List<T> list); static T first(Collection<T> list); static boolean containsAny(Collection<T> list, T... elements); static void removeLast(List<?> list); static Set<T> setOf(T... e); static M mergeWith(M target, Map<? extends K, ? extends V> source,
      BiFunction<? super V, ? super V, ? extends V> mergeFunc); static M mergeWith(
      M target, Map<? extends K, ? extends L> source); }
ListUtil { public static <V, S extends Collection<? extends V>, D extends Collection<? super V>> D takeBetween( S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest) { if (source != null) { boolean startTaking = false; for (V s : source) { if (!startTaking && dropPred.test(s)) continue; startTaking = true; if (!whilePred.test(s)) break; dest.add(s); } } return dest; }  static C map(
      Collection<? extends TSrc> source, BiFunction<? super TSrc, Integer, ? extends TDest> func, C dest); static C map(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends TDest> func, C dest); static List<TDest> map(
      Collection<? extends TSrc> source, BiFunction<? super TSrc, Integer, ? extends TDest> func); static List<TDest> map(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends TDest> func); static C flatMap(Collection<? extends TSrc> source,
      BiFunction<? super TSrc, Integer, ? extends Collection< ? extends TDest>> func, C dest); static C flatMap(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends Collection< ? extends TDest>> func, C dest); static List<TDest> flatMap(Collection<? extends TSrc> source,
      BiFunction<? super TSrc, Integer, ? extends Collection< ? extends TDest>> func); static List<TDest> flatMap(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends Collection< ? extends TDest>> func); static Set<TDest> unique(
      Collection<? extends TSrc> source, Function<? super TSrc, ? extends TDest> func); static List<TId> getIds(Collection<? extends Identifiable<TId>> identifiables); static Map<K, List<E>> groupBy(
      Collection<? extends E> source, Function<? super E, ? extends K> classifier); static Map<TK, TV> map(Map<? extends K, ? extends V> source,
      Function<? super K, ? extends TK> keyFunc, Function<? super V, ? extends TV> valFunc); static Map<K, TV> mapValues(
      Map<? extends K, ? extends V> source, Function<? super V, ? extends TV> valFunc); static Map<TK, V> mapKeys(
      Map<? extends K, ? extends V> source, Function<? super K, ? extends TK> keyFunc); static long[] toLongArray(Collection<Object> list); static Map<K, V> toMap(Collection<V> source, Function<? super V, ? extends K> keyFunc); static Map<K, V> toMap(
      Collection<S> source, Function<? super S, ? extends K> keyFunc, Function<? super S, ? extends V> valFunc); static D filter(
      S source, Predicate<? super V> pred, D dest); static List<V> filter(C source, Predicate<? super V> pred); static List<V> orderBy(
      C source, final Function<? super V, ? extends Comparable> by); static List<V> orderBy(
      C src, final Function<? super V, K> by, final boolean desc); static boolean contains(long[] longs, long match); static String join(T[] list, String delimiter); static String join(Collection<T> list, String delimiter); static boolean exists(C source, Predicate<? super V> pred); static V first(C source, Predicate<? super V> pred); static int indexOf(C source, Predicate<? super V> pred); static D takeBetween(
      S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred, D dest); static List<V> takeBetween(
      S source, Predicate<? super V> dropPred, Predicate<? super V> whilePred); static D takeWhile(
      S source, Predicate<? super V> pred, D dest); static List<V> takeWhile(S source, Predicate<? super V> pred); static D dropWhile(
      S source, Predicate<? super V> pred, D dest); static List<V> dropWhile(S source, Predicate<? super V> pred); static T last(List<T> list); static T first(Collection<T> list); static boolean containsAny(Collection<T> list, T... elements); static void removeLast(List<?> list); static Set<T> setOf(T... e); static M mergeWith(M target, Map<? extends K, ? extends V> source,
      BiFunction<? super V, ? super V, ? extends V> mergeFunc); static M mergeWith(
      M target, Map<? extends K, ? extends L> source);  }