/** * Creates a lazy Flow from the {@link Iterator} obtained from the iterable. The Flow * will be threadsafe as long as the iterable yields a new Iterator on each invocation <em>and</em> the underlying * iterable object is not modified while the Flow is evaluating. * In other words, not extremely threadsafe. */ public static <T> Flow<T> flow(Iterable<T> iterable) { assert iterable != null; return flow(iterable.iterator()); }
/** * Creates a lazy Flow from the {@link Iterator} obtained from the iterable. The Flow * will be threadsafe as long as the iterable yields a new Iterator on each invocation <em>and</em> the underlying * iterable object is not modified while the Flow is evaluating. * In other words, not extremely threadsafe. */ public static <T> Flow<T> flow(Iterable<T> iterable) { assert iterable != null; return flow(iterable.iterator()); }
@Override public Flow<T> concat(Collection<? extends T> collection) { return concat(F.flow(collection)); }
@Override public <V extends T> Flow<T> append(V... values) { return concat(F.flow(values)); }
@Override public <V extends T> Flow<T> append(V... values) { return concat(F.flow(values)); }
@Override public Flow<T> concat(Collection<? extends T> collection) { return concat(F.flow(collection)); }
/** * @since 5.3.1, 5.4 */ public static Object[] realizeObjects(ObjectCreator[] creators) { return F.flow(creators).map(CREATE_OBJECT).toArray(Object.class); }
private Flow<ServiceDef2> getLocalServiceDefs(final ModuleDef moduleDef) { return F.flow(moduleDef.getServiceIds()).map(new Mapper<String, ServiceDef2>() { @Override public ServiceDef2 map(String value) { return InternalUtils.toServiceDef2(moduleDef.getServiceDef(value)); } }); }
private Flow<PlasticMethod> matchEventHandlerMethods(PlasticClass plasticClass) { return F.flow(plasticClass.getMethods()).filter(new Predicate<PlasticMethod>() { public boolean accept(PlasticMethod method) { return "getClientId".equalsIgnoreCase(method.getDescription().methodName); } }); } }
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 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(); }
@Test public void IS_BLANK() { Flow<String> names = F.flow("red", "", "green", null, "blue"); assertFlowValues(names.remove(F.IS_BLANK), "red", "green", "blue"); } }
@Test public void flow_filter() { assertFlowValues(F.flow(1, 2, 3, 4, 5, 6, 7).filter(evenp), 2, 4, 6); }
public ToDoItem toValue(String clientValue) { final long id = Long.parseLong(clientValue); return F.flow(items).filter(new Predicate<ToDoItem>() { public boolean accept(ToDoItem element) { return element.getId() == id; } }).first(); }
@Test public void flow_remove() { List<Integer> output = F.flow(1, 2, 3, 4, 5, 6, 7).remove(evenp).toList(); assertListsEquals(output, 1, 3, 5, 7); }
@Test public void concat_empty_list() { Flow<Integer> flow = F.flow(1, 3); assertFlowValues(flow.concat(flow.filter(evenp)), 1, 3); }
@Test public void numeric_comparison() { List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); assertEquals(F.flow(input).filter(F.eq(3)).toList(), Arrays.asList(3)); assertEquals(F.flow(input).filter(F.neq(3)).toList(), Arrays.asList(1, 2, 4, 5, 6, 7)); assertEquals(F.flow(input).filter(F.lt(3)).toList(), Arrays.asList(1, 2)); assertEquals(F.flow(input).filter(F.lteq(3)).toList(), Arrays.asList(1, 2, 3)); assertEquals(F.flow(input).filter(F.gteq(3)).toList(), Arrays.asList(3, 4, 5, 6, 7)); }
@Test public void combine_mappers() { List<Boolean> even = F.flow("Mary", "had", "a", "little", "lamb").map(F.combine(stringToLength, toEven)) .toList(); assertListsEquals(even, true, false, false, true, true); }
@Test public void take_from_array_flow() { Flow<Integer> flow = F.flow(1, 2, 3, 4, 5); assertFlowValues(flow.take(2), 1, 2); assertFlowValues(flow.take(99), 1, 2, 3, 4, 5); assertSame(flow.take(0), F.EMPTY_FLOW); }
@Test public void count_of_a_mapped_filtered_empty_flow() { Flow<Integer> flow = F.flow("Mary", "had", "etc.").filter(F.isNull()).map(stringToLength); assertTrue(flow.isEmpty()); assertEquals(flow.count(), 0); }