@Override public Set<Tuple<A, B>> toSet() { return tupleFlow.toSet(); }
@Override public Set<Tuple<A, B>> toSet() { return tupleFlow.toSet(); }
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(); } }
/** * 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); } }
/** * 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); } }
@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(); }
@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(); }
@Test public void empty_flow_to_set() { assertSame(F.emptyFlow().toSet(), Collections.EMPTY_SET); }
@Test public void nonempty_flow() { Set<Integer> set = F.range(1, 10).filter(evenp).toSet(); assertTrue(set.containsAll(Arrays.asList(2, 4, 6, 8))); } }
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); }