public static <T> List<T> filter(final T[] xs, final Predicate<T> predicate) { final List<T> dest = new ArrayList<>(); filter(xs, predicate, dest); return dest; }
public boolean isGroovyClass() { return FArray.contains(this.interfaces, isAGroovyClass()); }
@Test public void shouldApplyFlatMapToAllItems() { final Function<Integer, Collection<Integer>> f = a -> Arrays.asList(a, a); final Collection<Integer> expected = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5); assertEquals(expected, FArray.flatMap(this.is, f)); }
@Test public void flatMapShouldTreatNullAsEmptyIterable() { assertEquals(Collections.emptyList(), FArray.flatMap(null, objectToObjectIterable())); }
public static Set<Method> publicMethods(final Class<?> clazz, final Predicate<Method> p) { final Set<Method> ms = new LinkedHashSet<>(); FArray.filter(clazz.getMethods(), p, ms); return ms; }
@Test public void containsShouldReturnTrueWhenPredicateMet() { final Integer[] xs = { 1, 2, 3 }; assertTrue(FArray.contains(xs, i -> true)); }
private static Collection<File> listFirstLevelDirectories(final File root) { return FArray.filter(root.listFiles(), a -> a.isDirectory()); }
@Test public void containsShouldStopProcessingOnFirstMatch() { final Integer[] xs = { 1, 2, 3 }; final Predicate<Integer> predicate = a -> { if (a == 2) { throw new PitError("Did not shortcut"); } return a == 1; }; FArray.contains(xs, predicate); // pass }
@Test public void shouldReturnEmptyListWhenGivenNull() { assertEquals(Collections.emptyList(), FArray.filter(null, i -> true)); }
@Test public void containsShouldReturnFalseWhenPredicateNotMet() { final Integer[] xs = { 1, 2, 3 }; assertFalse(FArray.contains(xs, False.instance())); }
@Test public void shouldReturnOnlyMatchesToPredicate() { final Predicate<Integer> p = a -> a <= 2; final List<Integer> expected = Arrays.asList(1, 2); assertEquals(expected, FArray.filter(this.is, p)); }
public boolean isGroovyClass() { return FArray.contains(this.interfaces, isAGroovyClass()); }
@Test public void shouldReturnAllEntriesWhenFilteredOnTrue() { final List<Integer> expected = Arrays.asList(this.is); assertEquals(expected, FArray.filter(this.is, i -> true)); }
@Test public void shouldReturnEmptyListWhenFilteredOnFalse() { final List<Integer> expected = Collections.emptyList(); assertEquals(expected, FArray.filter(this.is, False.instance())); }
public static <T> List<T> filter(final T[] xs, final Predicate<T> predicate) { final List<T> dest = new ArrayList<>(); filter(xs, predicate, dest); return dest; }
public static Set<Method> publicMethods(final Class<?> clazz, final Predicate<Method> p) { final Set<Method> ms = new LinkedHashSet<>(); FArray.filter(clazz.getMethods(), p, ms); return ms; }