ListUtils { public static <T> Replacement<T> replaceIn(List<T> list) { return new Replacement<>(list); } private  ListUtils(); static int firstIndexOf(List<? extends T> list, Predicate<? super T> predicate); static boolean addIfNotPresent(List<? super T> list, T element); static boolean addIfNotPresent(List<? super T> list, int index, T element); static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, List<T>> joining(Supplier<? extends T> separator); static Collector<T, ?, List<T>> joining(Supplier<? extends T> prefix,
                                                     Supplier<? extends T> separator,
                                                     Supplier<? extends T> suffix); static Replacement<T> replaceIn(List<T> list);  }
@Test public void testReplaceFirst() { List<String> list = Arrays.asList(foo, foo, bar); ListUtils.replaceIn(list) .replace(foo) .first() .with(bar); assertEquals(Arrays.asList(bar, foo, bar), list); }
@Test public void testReplaceAll() { List<String> list = Arrays.asList(foo, foo, bar); ListUtils.replaceIn(list) .replace(foo) .all() .with(bar); assertEquals(Arrays.asList(bar, bar, bar), list); }
@Test public void testThrowsWhenNoSearchValueSet() { assertThrows(IllegalStateException.class, () -> ListUtils.replaceIn(new ArrayList<>()).with(() -> null)); }