@SuppressWarnings("rawtypes") private Set<Class> extractMarkers(Method method, final Class... annotationClassesToSkip) { return F.flow(method.getAnnotations()).map(new Mapper<Annotation, Class>() { @Override public Class map(Annotation value) { return value.annotationType(); } }).filter(new Predicate<Class>() { @Override public boolean accept(Class element) { for (Class skip : annotationClassesToSkip) { if (skip.equals(element)) { return false; } } return true; } }).toSet(); }
private ComponentIdValidator[] extractComponentIdValidators(Flow<EventHandlerMethod> eventHandlerMethods) { return eventHandlerMethods.map(new Mapper<EventHandlerMethod, ComponentIdValidator>() { public ComponentIdValidator map(EventHandlerMethod element) { if (element.componentId.equals("")) { return null; } return new ComponentIdValidator(element.componentId, element.method.getMethodIdentifier()); } }).removeNulls().toArray(ComponentIdValidator.class); }
assertFlowValues(F.range(1, 100).filter(F.gt(10)).map(doubler).take(3), 22, 24, 26); assertEquals(F.range(1, 100).map(doubler).count(), 99); assertEquals(count.get(), 0); Flow<Integer> flow = F.range(1, 100).map(doubler).concat(F.range(1, 10).map(doubler)); assertEquals(flow.count(), 108); assertEquals(count.get(), 0); assertFlowValues(flow.take(2), 2, 4); assertEquals(count.get(), 2); assertFlowValues(flow.take(3), 2, 4, 6); assertEquals(count.get(), 1);
@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)); }
public Set<Page> getAllPages() { return F.flow(pageCache.values()).map(new Mapper<SoftReference<Page>, Page>() { public Page map(SoftReference<Page> element) { return element.get(); } }).removeNulls().toSet(); } }
public void onRecomputeTotals() { totals = new PageCatalogTotals(); Flow<Page> pages = F.flow(getPages()); totals.loadedPages = pages.count(); totals.definedPages = getPageNames().size(); totals.uniquePageNames = pages.map(new Mapper<Page, String>() { public String map(Page element) { return element.getName(); } }).toSet().size(); totals.components = pages.reduce(new Reducer<Integer, Page>() { public Integer reduce(Integer accumulator, Page element) { return accumulator + element.getStats().componentCount; } }, 0); Set<String> selectorIds = pages.map(new Mapper<Page, String>() { public String map(Page element) { return element.getSelector().toShortString(); } }).toSet(); totals.selectors = InternalUtils.joinSorted(selectorIds); }
/** * Synchronization should not be necessary, but perhaps the underlying ClassLoader's are sensitive to threading. */ @Override public synchronized Collection<String> locateClassNames(String packageName) { String packagePath = packageName.replace('.', '/') + "/"; try { Collection<String> matches = scanner.scan(packagePath, CLASS_NAME_MATCHER); return F.flow(matches).map(CLASS_NAME_MAPPER).toSet(); } catch (IOException ex) { throw new RuntimeException(ex); } }
@Test public void count_of_a_filtered_flow() { Flow<String> flow = F.flow("Mary", "had", "a", "little", "lamb"); assertEquals(flow.filter(F.isNull()).count(), 0); assertEquals(flow.removeNulls().count(), 5); }
public void render(MarkupWriter writer, final RenderQueue queue) { writer.element("ul"); queue.push(RENDER_CLOSE_TAG); queue.push(toRenderCommand(nodes.first(), true)); nodes.rest().each(new Worker<TreeNode>() { public void work(TreeNode element) { queue.push(toRenderCommand(element, false)); } }); }
@Override public List coerce(Flow input) { return input.toList(); } }));