@Override public List<Tuple<A, B>> toList() { return tupleFlow.toList(); }
private List<Class> toProviderClasses(final List<PersistenceProvider> providers) { return F.flow(providers).map(new Mapper<PersistenceProvider, Class>() { @Override public Class map(PersistenceProvider element) { return element.getClass(); } }).toList(); }
private static <T> List<T> extend(List<T> list, T extraValue) { return F.flow(list).append(extraValue).toList(); } }
private List<String> toPaths(List<Asset> assets) { assert assets != null; return F.flow(assets).map(toPath).toList(); }
public List<String> getLibraryNames() { return F.flow(libraryNameToPackageNames.keySet()).remove(F.IS_BLANK).sort().toList(); }
@Override public AnnotationProvider getClassAnnotationProvider() { return AnnotationProviderChain.create(searchPath().map(InternalUtils.CLASS_TO_AP_MAPPER).toList()); }
@Override public AnnotationProvider getClassAnnotationProvider() { return AnnotationProviderChain.create(searchPath().map(InternalUtils.CLASS_TO_AP_MAPPER).toList()); }
@Override public AnnotationProvider getMethodAnnotationProvider(final String methodName, final Class... argumentTypes) { return AnnotationProviderChain.create(searchPath().map(new Mapper<Class, Method>() { @Override public Method map(Class element) { return InternalUtils.findMethod(element, methodName, argumentTypes); } }).map(InternalUtils.METHOD_TO_AP_MAPPER).toList()); }
@Override public AnnotationProvider getMethodAnnotationProvider(final String methodName, final Class... argumentTypes) { return AnnotationProviderChain.create(searchPath().map(new Mapper<Class, Method>() { @Override public Method map(Class element) { return InternalUtils.findMethod(element, methodName, argumentTypes); } }).map(InternalUtils.METHOD_TO_AP_MAPPER).toList()); }
@Test public void remove() { List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); List<Integer> output = F.flow(input).remove(evenp).toList(); assertListsEquals(output, 1, 3, 5, 7); }
@Test public void map() { List<String> source = Arrays.asList("Mary", "had", "a", "little", "lamb"); List<Integer> lengths = F.flow(source).map(stringToLength).toList(); assertListsEquals(lengths, 4, 3, 1, 6, 4); }
@Test public void map_empty_collection_is_the_empty_list() { List<String> source = Arrays.asList(); List<Integer> lengths = F.flow(source).map(stringToLength).toList(); assertSame(lengths, Collections.EMPTY_LIST); }
@Test public void filter_empty_is_the_empty_list() { List<Integer> input = Arrays.asList(); List<Integer> output = F.flow(input).filter(evenp).toList(); assertSame(output, Collections.EMPTY_LIST); }
@Test public void filter() { List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); List<Integer> output = F.flow(input).filter(evenp).toList(); assertListsEquals(output, 2, 4, 6); }
@Test public void list_of_empty_flow_is_empty() { assertTrue(filteredEmpty.isEmpty()); assertSame(filteredEmpty.toList(), Collections.EMPTY_LIST); }
@Test public void eql_predicate() { List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); List<Integer> output = F.flow(input).filter(F.eql(4)).toList(); assertListsEquals(output, 4); }
@Test public void combine_predicate_with_or() { List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); List<Integer> output = F.flow(input).filter(F.or(F.lt(3), F.gt(5))).toList(); assertListsEquals(output, 1, 2, 6, 7); }
@Test public void array_flow_reduce() { int total = F.flow(F.flow("Mary", "had", "a", "little", "lamb").map(stringToLength).toList()).reduce( F.SUM_INTS, 0); assertEquals(total, 18); }
@Test public void combine_predicate_with_and() { List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); List<Integer> output = F.flow(input).filter(F.and(F.gt(2), F.lt(5))).toList(); assertListsEquals(output, 3, 4); }
@Test public void select_and_filter() { Predicate<String> combinedp = F.toPredicate(F.combine(stringToLength, toEven)); Mapper<String, String> identity = F.identity(); Predicate<String> isNull = F.isNull(); // Converting to null and then filtering out nulls is the hard way to do filter or remove, // but exercises the code we want to test. List<String> filtered = F.flow("Mary", "had", "a", "little", "lamb").map(F.select(combinedp, identity)) .remove(isNull).toList(); assertListsEquals(filtered, "Mary", "little", "lamb"); }