@Override public ZippedFlow<A, B> each(Worker<? super Tuple<A, B>> worker) { tupleFlow.each(worker); return this; }
@Override public ZippedFlow<A, B> each(Worker<? super Tuple<A, B>> worker) { tupleFlow.each(worker); return this; }
@Override public Map<A, B> toMap() { final Map<A, B> result = new HashMap<A, B>(); tupleFlow.each(new Worker<Tuple<A, B>>() { @Override public void work(Tuple<A, B> value) { result.put(value.first, value.second); } }); return result; } }
@Override public Map<A, B> toMap() { final Map<A, B> result = new HashMap<A, B>(); tupleFlow.each(new Worker<Tuple<A, B>>() { @Override public void work(Tuple<A, B> value) { result.put(value.first, value.second); } }); return result; } }
public void advise(MethodInvocation invocation) { assetFlow.each(importLibrary); invocation.proceed(); } });
/** * Fires the {@link RegistryShutdownListener#registryDidShutdown()} method on each listener. At the end, all the * listeners are discarded. */ public void fireRegistryDidShutdown() { lock.lock(); F.flow(preListeners).concat(listeners).each(new Worker<Runnable>() { @Override public void work(Runnable element) { try { element.run(); } catch (RuntimeException ex) { logger.error(ServiceMessages.shutdownListenerError(element, ex), ex); } } }); preListeners.clear(); listeners.clear(); }
private Flow<PlasticMethod> matchLifecycleMethods(PlasticClass plasticClass) { return F.flow(plasticClass.getMethods()).filter(MATCHER).each(VALIDATE); } }
/** * Fires the {@link RegistryShutdownListener#registryDidShutdown()} method on each listener. At the end, all the * listeners are discarded. */ public void fireRegistryDidShutdown() { lock.lock(); F.flow(preListeners).concat(listeners).each(new Worker<Runnable>() { @Override public void work(Runnable element) { try { element.run(); } catch (RuntimeException ex) { logger.error(ServiceMessages.shutdownListenerError(element, ex), ex); } } }); preListeners.clear(); listeners.clear(); }
private Flow<PlasticMethod> findResetMethods(PlasticClass plasticClass) { return F.flow(plasticClass.getMethods()).filter(METHOD_MATCHER).each(METHOD_VALIDATOR); } }
/** * Iterates over the values, passing each in turn to the supplied worker. * * @param worker * performs an operation on, or using, the value */ public void eachValue(Worker<T> worker) { Collection<T> result = CollectionFactory.newList(); addValues(result); F.flow(result).each(worker); }
public void render(MarkupWriter writer, RenderQueue queue, DynamicDelegate delegate) { // Write the element ... writer.elementNS(elementURI, elementName); // ... and the attributes for (DynamicTemplateAttribute attribute : attributes) { attribute.write(writer, delegate); } // And convert the DTEs for the direct children of this element into RenderCommands and push them onto // the queue. This includes the child that will end the started element. Mapper<DynamicTemplateElement, RenderCommand> toRenderCommand = createToRenderCommandMapper(delegate); Worker<RenderCommand> pushOnQueue = createQueueRenderCommand(queue); bodyFlow.map(toRenderCommand).each(pushOnQueue); } };
public void advise(MethodInvocation invocation) { invocation.proceed(); Asset[] assets = (Asset[]) access.get(invocation.getInstance()); F.flow(assets).each(operation); } });
public void commit() { if (focusFieldId != null) { require("t5/core/pageinit").invoke("focus").with(focusFieldId); } F.flow(stylesheetLinks).each(new Worker<StylesheetLink>() { public void work(StylesheetLink value) { linker.addStylesheetLink(value); } }); F.flow(inits).sort(new Comparator<InitializationImpl>() { public int compare(InitializationImpl o1, InitializationImpl o2) { return o1.priority.compareTo(o2.priority); } }).each(new Worker<InitializationImpl>() { public void work(InitializationImpl element) { linker.addInitialization(element.priority, element.moduleName, element.functionName, element.arguments); } }); }
public static JSONObject convertInformalParametersToJson( final ComponentResources resources, final String prefix) { final JSONObject json = new JSONObject(); F.flow(resources.getInformalParameterNames()).filter(new Predicate<String>() { public boolean accept(String param) { return param.startsWith(prefix); } }).each(new Worker<String>() { public void work(String params) { json.put(params.substring(prefix.length()), resources.getInformalParameter(params, String.class)); } }); return json; }
@Test public void each_on_empty_flow() { Flow<Integer> flow = F.emptyFlow(); assertSame(flow.each(new Worker<Integer>() { @Override public void work(Integer value) { unreachable(); } }), flow); }
@Test public void each() { List<String> source = Arrays.asList("Mary", "had", "a", "little", "lamb"); final StringBuffer buffer = new StringBuffer(); Worker<String> worker = new Worker<String>() { @Override public void work(String value) { if (buffer.length() > 0) buffer.append(' '); buffer.append(value); } }; F.flow(source).each(worker); assertEquals(buffer.toString(), "Mary had a little lamb"); }
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)); } }); }
@Test public void flow_each() { Flow<String> flow = F.flow("Mary", "had", "a", "little", "lamb"); final StringBuffer buffer = new StringBuffer(); Worker<String> worker = new Worker<String>() { @Override public void work(String value) { if (buffer.length() > 0) buffer.append(' '); buffer.append(value); } }; assertSame(flow.each(worker), flow); assertEquals(buffer.toString(), "Mary had a little lamb"); }
@Test public void each_on_non_array_flow() { List<String> source = Arrays.asList("Mary", "had", "a", "little", "lamb"); final StringBuffer buffer = new StringBuffer(); Worker<String> worker = new Worker<String>() { @Override public void work(String value) { if (buffer.length() > 0) buffer.append(' '); buffer.append(value); } }; F.flow(source).filter(new Predicate<String>() { @Override public boolean accept(String object) { return object.contains("a"); } }).each(worker); assertEquals(buffer.toString(), "Mary had a lamb"); }
@Test public void combine_workers() { final StringBuffer buffer = new StringBuffer(); Worker<String> appendWorker = new Worker<String>() { @Override public void work(String value) { if (buffer.length() > 0) buffer.append(' '); buffer.append(value); } }; Worker<String> appendLength = new Worker<String>() { @Override public void work(String value) { buffer.append('('); buffer.append(value.length()); buffer.append(')'); } }; F.flow("Mary", "had", "a", "little", "lamb").each(F.combine(appendWorker, appendLength)); assertEquals(buffer.toString(), "Mary(4) had(3) a(1) little(6) lamb(4)"); }