public RenderNodes(List<TreeNode> nodes) { assert !nodes.isEmpty(); this.nodes = F.flow(nodes).reverse(); }
@Override public ZippedFlow<A, B> reverse() { return create(tupleFlow.reverse()); }
@Override public ZippedFlow<A, B> reverse() { return create(tupleFlow.reverse()); }
private static DynamicTemplate toDynamicTemplate(List<DynamicTemplateElement> elements) { final Flow<DynamicTemplateElement> flow = F.flow(elements).reverse(); return new DynamicTemplate() { public RenderCommand createRenderCommand(final DynamicDelegate delegate) { final Mapper<DynamicTemplateElement, RenderCommand> toRenderCommand = createToRenderCommandMapper(delegate); return new RenderCommand() { public void render(MarkupWriter writer, RenderQueue queue) { Worker<RenderCommand> pushOnQueue = createQueueRenderCommand(queue); flow.map(toRenderCommand).each(pushOnQueue); } }; } }; }
private static DynamicTemplateElement createElementWriterElement(final String elementURI, final String elementName, final List<DynamicTemplateAttribute> attributes, List<DynamicTemplateElement> body) { final Flow<DynamicTemplateElement> bodyFlow = F.flow(body).reverse(); return new DynamicTemplateElement() { 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); } }; }
@Test public void flow_reverse() { assertFlowValues(F.flow(1, 2, 3).reverse(), 3, 2, 1); }
@Test public void reverse_non_array_flow() { assertFlowValues(filteredEmpty.append(1, 2, 3).reverse(), 3, 2, 1); }
reverse ? F.flow(methods).reverse() : F.flow(methods);
@Test public void drop_from_array_flow() { assertFlowValues(F.range(1, 10).reverse().drop(2), 7, 6, 5, 4, 3, 2, 1); } }
/** * Assembles a set of properties appropriate for the bundle in question, and the desired locale. The properties * reflect the properties of the bundles' parent (if any) for the locale, overalyed with any properties defined for * this bundle and its locale. */ private Map<String, String> findBundleProperties(MessagesBundle bundle, ComponentResourceSelector selector) { if (bundle == null) return emptyMap; MultiKey key = new MultiKey(bundle.getId(), selector); Map<String, String> existing = cookedProperties.get(key); if (existing != null) return existing; // What would be cool is if we could maintain a cache of bundle id + locale --> // Resource. That would optimize quite a bit of this; may need to use an alternative to // LocalizedNameGenerator. Resource propertiesResource = bundle.getBaseResource().withExtension("properties"); List<Resource> localizations = resourceLocator.locateMessageCatalog(propertiesResource, selector); // Localizations are now in least-specific to most-specific order. Map<String, String> previous = findBundleProperties(bundle.getParent(), selector); for (Resource localization : F.flow(localizations).reverse()) { Map<String, String> rawProperties = getRawProperties(localization); // Woould be nice to write into the cookedProperties cache here, // but we can't because we don't know the selector part of the MultiKey. previous = extend(previous, rawProperties); } cookedProperties.put(key, previous); return previous; }
@Test public void operations_on_empty_list_yield_empty() { assertSame(filteredEmpty.reverse(), F.EMPTY_FLOW); assertSame(filteredEmpty.sort(), F.EMPTY_FLOW); assertSame(filteredEmpty.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { unreachable(); return 0; } }), F.EMPTY_FLOW); }