It looks like you changed your source formatting settings... On Fri, Jan 7, 2011 at 1:31 PM, <[email protected]> wrote: > Author: hlship > Date: Fri Jan 7 21:31:05 2011 > New Revision: 1056524 > > URL: http://svn.apache.org/viewvc?rev=1056524&view=rev > Log: > TAP5-1390: Convert Predicate, Mapper and Worker from abstract base classes > to single method interfaces (for future lambda compatibility) > Move other operations to static methods of F > > Modified: > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/AbstractFlow.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/F.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper2.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Predicate.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Worker.java > > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/ZippedFlowImpl.java > > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java > > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java > > tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java > Fri Jan 7 21:31:05 2011 > @@ -1,10 +1,10 @@ > -// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation > +// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software > Foundation > // > // Licensed under the Apache License, Version 2.0 (the "License"); > // you may not use this file except in compliance with the License. > // You may obtain a copy of the License at > // > -// http://www.apache.org/licenses/LICENSE-2.0 > +// http://www.apache.org/licenses/LICENSE-2.0 > // > // Unless required by applicable law or agreed to in writing, software > // distributed under the License is distributed on an "AS IS" BASIS, > @@ -52,7 +52,7 @@ public final class Element extends Node > private static final String CLASS_ATTRIBUTE = "class"; > > /** > - * URI of the namespace which contains the element. A quirk in XML is > that the element may be in a namespace it > + * URI of the namespace which contains the element. A quirk in XML is > that the element may be in a namespace it > * defines itself, so resolving the namespace to a prefix must wait until > render time (since the Element is created > * before the namespaces for it are defined). > */ > @@ -93,7 +93,7 @@ public final class Element extends Node > > /** > * Returns the containing element for this element. This will be null for > the root element of a document. > - * > + * > * @deprecated since 5.1.0.1, use {...@link Node#getContainer()} instead > */ > public Element getParent() > @@ -103,10 +103,12 @@ public final class Element extends Node > > /** > * Adds an attribute to the element, but only if the attribute name does > not already exist. > - * > - * @param name the name of the attribute to add > - * @param value the value for the attribute. A value of null is allowed, > and no attribute will be added to the > - * element. > + * > + * @param name > + * the name of the attribute to add > + * @param value > + * the value for the attribute. A value of null is allowed, > and no attribute will be added to the > + * element. > */ > public Element attribute(String name, String value) > { > @@ -115,11 +117,14 @@ public final class Element extends Node > > /** > * Adds a namespaced attribute to the element, but only if the attribute > name does not already exist. > - * > - * @param namespace the namespace to contain the attribute, or null > - * @param name the name of the attribute to add > - * @param value the value for the attribute. A value of null is > allowed, and no attribute will be added to the > - * element. > + * > + * @param namespace > + * the namespace to contain the attribute, or null > + * @param name > + * the name of the attribute to add > + * @param value > + * the value for the attribute. A value of null is allowed, > and no attribute will be added to the > + * element. > */ > public Element attribute(String namespace, String name, String value) > { > @@ -131,7 +136,8 @@ public final class Element extends Node > > private void updateAttribute(String namespace, String name, String value, > boolean force) > { > - if (!force && value == null) return; > + if (!force && value == null) > + return; > > Attribute prior = null; > Attribute cursor = firstAttribute; > @@ -140,7 +146,8 @@ public final class Element extends Node > { > if (cursor.matches(namespace, name)) > { > - if (!force) return; > + if (!force) > + return; > > if (value != null) > { > @@ -162,18 +169,19 @@ public final class Element extends Node > cursor = cursor.nextAttribute; > } > > - // Don't add a Attribute if the value is null. > + // Don't add a Attribute if the value is null. > > - if (value == null) return; > + if (value == null) > + return; > > firstAttribute = new Attribute(this, namespace, name, value, > firstAttribute); > } > > - > /** > * Convenience for invoking {...@link #attribute(String, String)} > multiple times. > - * > - * @param namesAndValues alternating attribute names and attribute values > + * > + * @param namesAndValues > + * alternating attribute names and attribute values > */ > public Element attributes(String... namesAndValues) > { > @@ -192,8 +200,9 @@ public final class Element extends Node > /** > * Forces changes to a number of attributes. The new attributes > <em>overwrite</em> previous values. Overriding an > * attribute's value to null will remove the attribute entirely. > - * > - * @param namesAndValues alternating attribute names and attribute values > + * > + * @param namesAndValues > + * alternating attribute names and attribute values > * @return this element > */ > public Element forceAttributes(String... namesAndValues) > @@ -205,11 +214,12 @@ public final class Element extends Node > * Forces changes to a number of attributes in the global namespace. The > new attributes <em>overwrite</em> previous > * values. Overriding attribute's value to null will remove the attribute > entirely. > * TAP5-708: don't use element namespace for attributes > - * > - * @param namespace the namespace or null > - * @param namesAndValues alternating attribute name and value > + * > + * @param namespace > + * the namespace or null > + * @param namesAndValues > + * alternating attribute name and value > * @return this element > - * > */ > public Element forceAttributesNS(String namespace, String... > namesAndValues) > { > @@ -228,9 +238,11 @@ public final class Element extends Node > > /** > * Creates and returns a new Element node as a child of this node. > - * > - * @param name the name of the element to create > - * @param namesAndValues alternating attribute names and attribute values > + * > + * @param name > + * the name of the element to create > + * @param namesAndValues > + * alternating attribute names and attribute values > */ > public Element element(String name, String... namesAndValues) > { > @@ -244,9 +256,11 @@ public final class Element extends Node > > /** > * Creates and returns a new Element within a namespace as a child of > this node. > - * > - * @param namespace namespace to contain the element, or null > - * @param name element name to create within the namespace > + * > + * @param namespace > + * namespace to contain the element, or null > + * @param name > + * element name to create within the namespace > * @return the newly created element > */ > public Element elementNS(String namespace, String name) > @@ -287,10 +301,11 @@ public final class Element extends Node > } > > /** > - * Adds and returns a new text node (the text node is returned so that > {...@link Text#write(String)} or [...@link {...@link > - * Text#writef(String, Object[])} may be invoked . > - * > - * @param text initial text for the node > + * Adds and returns a new text node (the text node is returned so that > {...@link Text#write(String)} or [...@link > + * {...@link Text#writef(String, Object[])} may be invoked . > + * > + * @param text > + * initial text for the node > * @return the new Text node > */ > public Text text(String text) > @@ -300,8 +315,9 @@ public final class Element extends Node > > /** > * Adds and returns a new CDATA node. > - * > - * @param content the content to be rendered by the node > + * > + * @param content > + * the content to be rendered by the node > * @return the newly created node > */ > public CData cdata(String content) > @@ -309,7 +325,6 @@ public final class Element extends Node > return newChild(new CData(this, content)); > } > > - > private <T extends Node> T newChild(T child) > { > addChild(child); > @@ -344,7 +359,8 @@ public final class Element extends Node > > for (String namespace : namespaces) > { > - if (namespace.equals(Document.XML_NAMESPACE_URI)) continue; > + if (namespace.equals(Document.XML_NAMESPACE_URI)) > + continue; > > String prefix = namespaceToPrefix.get(namespace); > > @@ -373,12 +389,14 @@ public final class Element extends Node > > writer.print(builder.toString()); > > - if (hasChildren) writeChildMarkup(document, writer, > localNamespacePrefixToURI); > + if (hasChildren) > + writeChildMarkup(document, writer, localNamespacePrefixToURI); > > // Dangerous -- perhaps it should be an error for a tag of type OMIT > to even have children! > // We'll certainly be writing out unbalanced markup in that case. > > - if (style == EndTagStyle.OMIT) return; > + if (style == EndTagStyle.OMIT) > + return; > > if (hasChildren || style == EndTagStyle.REQUIRE) > { > @@ -391,21 +409,24 @@ public final class Element extends Node > > String toPrefixedName(Map<String, String> namespaceURIToPrefix, String > namespace, String name) > { > - if (namespace == null || namespace.equals("")) return name; > + if (namespace == null || namespace.equals("")) > + return name; > > - if (namespace.equals(Document.XML_NAMESPACE_URI)) return "xml:" + > name; > + if (namespace.equals(Document.XML_NAMESPACE_URI)) > + return "xml:" + name; > > String prefix = namespaceURIToPrefix.get(namespace); > > // This should never happen, because namespaces are automatically > defined as needed. > > if (prefix == null) > - throw new IllegalArgumentException( > - String.format("No prefix has been defined for namespace > '%s'.", namespace)); > + throw new IllegalArgumentException(String.format("No prefix has > been defined for namespace '%s'.", > + namespace)); > > // The empty string indicates the default namespace which doesn't use > a prefix. > > - if (prefix.equals("")) return name; > + if (prefix.equals("")) > + return name; > > return prefix + ":" + name; > } > @@ -420,16 +441,16 @@ public final class Element extends Node > * @return the element if found. null if not found. > */ > public Element getElementById(final String id) > - { > + { > return getElementByAttributeValue("id", id); > } > - > + > /** > * Tries to find an element under this element (including itself) whose > given attribute has a given value. > * > * @since 5.2.3 > - * > - * @param attributeName the name of the attribute of the element being > looked for > + * @param attributeName > + * the name of the attribute of the element being looked for > * @param attributeValue > * the value of the attribute of the element being looked for > * @return the element if found. null if not found. > @@ -438,11 +459,9 @@ public final class Element extends Node > { > assert attributeName != null; > assert attributeValue != null; > - > + > return getElement(new Predicate<Element>() > { > - > - �...@override > public boolean accept(Element e) > { > String elementId = e.getAttribute(attributeName); > @@ -455,8 +474,8 @@ public final class Element extends Node > * Tries to find an element under this element (including itself) > accepted by the given predicate. > * > * @since 5.2.3 > - * > - * @param predicate Predicate to accept the element > + * @param predicate > + * Predicate to accept the element > * @return the element if found. null if not found. > */ > public Element getElement(Predicate<Element> predicate) > @@ -469,7 +488,8 @@ public final class Element extends Node > { > Element e = queue.removeFirst(); > > - if (predicate.accept(e)) return e; > + if (predicate.accept(e)) > + return e; > > for (Element child : e.childElements()) > { > @@ -482,11 +502,10 @@ public final class Element extends Node > return null; > } > > - > /** > * Searchs for a child element with a particular name below this element. > The path parameter is a slash separated > * series of element names. > - * > + * > * @param path > * @return > */ > @@ -499,7 +518,8 @@ public final class Element extends Node > { > search = search.findChildWithElementName(name); > > - if (search == null) break; > + if (search == null) > + break; > } > > return search; > @@ -536,7 +556,8 @@ public final class Element extends Node > { > while (cursor != null) > { > - if (cursor instanceof Element) return; > + if (cursor instanceof Element) > + return; > > cursor = cursor.nextSibling; > } > @@ -586,8 +607,9 @@ public final class Element extends Node > /** > * Adds one or more CSS class names to the "class" attribute. No check > for duplicates is made. Note that CSS class > * names are case insensitive on the client. > - * > - * @param className one or more CSS class names > + * > + * @param className > + * one or more CSS class names > * @return the element for further configuration > */ > public Element addClassName(String... className) > @@ -596,11 +618,13 @@ public final class Element extends Node > > StringBuilder builder = new StringBuilder(); > > - if (classes != null) builder.append(classes); > + if (classes != null) > + builder.append(classes); > > for (String name : className) > { > - if (builder.length() > 0) builder.append(" "); > + if (builder.length() > 0) > + builder.append(" "); > > builder.append(name); > } > @@ -611,12 +635,14 @@ public final class Element extends Node > } > > /** > - * Defines a namespace for this element, mapping a URI to a prefix. > This will affect how namespaced elements and > + * Defines a namespace for this element, mapping a URI to a prefix. This > will affect how namespaced elements and > * attributes nested within the element are rendered, and will also cause > <code>xmlns:</code> attributes (to define > * the namespace and prefix) to be rendered. > - * > - * @param namespace URI of the namespace > - * @param namespacePrefix prefix > + * > + * @param namespace > + * URI of the namespace > + * @param namespacePrefix > + * prefix > * @return this element > */ > public Element defineNamespace(String namespace, String namespacePrefix) > @@ -647,7 +673,7 @@ public final class Element extends Node > */ > public void pop() > { > - // Have to be careful because we'll be modifying the underlying > list of children > + // Have to be careful because we'll be modifying the underlying list > of children > // as we work, so we need a copy of the children. > > List<Node> childrenCopy = CollectionFactory.newList(getChildren()); > @@ -662,7 +688,7 @@ public final class Element extends Node > > /** > * Removes all children from this element. > - * > + * > * @return the element, for method chaining > */ > public Element removeChildren() > @@ -677,7 +703,7 @@ public final class Element extends Node > * Creates the URI to namespace prefix map for this element, which > reflects namespace mappings from containing > * elements. In addition, automatic namespaces are defined for any URIs > that are not explicitly mapped (this occurs > * sometimes in Ajax partial render scenarios). > - * > + * > * @return a mapping from namespace URI to namespace prefix > */ > private Map<String, String> createNamespaceURIToPrefix(Map<String, > String> containerNamespaceURIToPrefix) > @@ -686,7 +712,6 @@ public final class Element extends Node > > holder.putAll(namespaceToPrefix); > > - > // result now contains all the mappings, including this element's. > > // Add a mapping for the element's namespace. > @@ -713,11 +738,13 @@ public final class Element extends Node > > private void addMappingIfNeeded(MapHolder holder, String namespace) > { > - if (InternalUtils.isBlank(namespace)) return; > + if (InternalUtils.isBlank(namespace)) > + return; > > Map<String, String> current = holder.getResult(); > > - if (current.containsKey(namespace)) return; > + if (current.containsKey(namespace)) > + return; > > // A missing namespace. > > @@ -768,14 +795,15 @@ public final class Element extends Node > > /** > * Returns true if the element has no children, or has only text children > that contain only whitespace. > - * > + * > * @since 5.1.0.0 > */ > public boolean isEmpty() > { > List<Node> children = getChildren(); > > - if (children.isEmpty()) return true; > + if (children.isEmpty()) > + return true; > > for (Node n : children) > { > @@ -783,7 +811,8 @@ public final class Element extends Node > { > Text t = (Text) n; > > - if (t.isEmpty()) continue; > + if (t.isEmpty()) > + continue; > } > > // Not a text node, or a non-empty text node, then the element > isn't empty. > @@ -796,8 +825,9 @@ public final class Element extends Node > /** > * Depth-first visitor traversal of this Element and its Element > children. The traversal order is the same as render > * order. > - * > - * @param visitor callback > + * > + * @param visitor > + * callback > * @since 5.1.0.0 > */ > public void visit(Visitor visitor) > @@ -816,10 +846,10 @@ public final class Element extends Node > } > } > > - > private void queueChildren(Stack<Element> queue) > { > - if (firstChild == null) return; > + if (firstChild == null) > + return; > > List<Element> childElements = CollectionFactory.newList(); > > @@ -867,7 +897,6 @@ public final class Element extends Node > cursor = cursor.nextSibling; > } > > - > newChild.nextSibling = cursor.nextSibling; > cursor.nextSibling = newChild; > } > @@ -910,9 +939,9 @@ public final class Element extends Node > > /** > * Returns an unmodifiable list of children for this element. Only > {...@link org.apache.tapestry5.dom.Element}s will > - * have children. Also, note that unlike W3C DOM, attributes are not > represented as {...@link > - * org.apache.tapestry5.dom.Node}s. > - * > + * have children. Also, note that unlike W3C DOM, attributes are not > represented as > + * {...@link org.apache.tapestry5.dom.Node}s. > + * > * @return unmodifiable list of children nodes > */ > @SuppressWarnings("unchecked") > @@ -993,7 +1022,8 @@ public final class Element extends Node > > while (cursor != null) > { > - if (node == cursor) return index; > + if (node == cursor) > + return index; > > cursor = cursor.nextSibling; > index++; > @@ -1003,11 +1033,11 @@ public final class Element extends Node > } > > /** > - * Returns the attributes for this Element as a (often empty) collection > of {...@link > - * org.apache.tapestry5.dom.Attribute}s. The order of the attributes > within the collection is not specified. > + * Returns the attributes for this Element as a (often empty) collection > of > + * {...@link org.apache.tapestry5.dom.Attribute}s. The order of the > attributes within the collection is not specified. > * Modifying the collection will not affect the attributes (use {...@link > #forceAttributes(String[])} to change > * existing attribute values, and {...@link #attribute(String, String, > String)} to add new attribute values. > - * > + * > * @return attribute collection > */ > public Collection<Attribute> getAttributes() > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java > Fri Jan 7 21:31:05 2011 > @@ -1,4 +1,4 @@ > -// Copyright 2010 The Apache Software Foundation > +// Copyright 2010, 2011 The Apache Software Foundation > // > // Licensed under the Apache License, Version 2.0 (the "License"); > // you may not use this file except in compliance with the License. > @@ -57,8 +57,8 @@ public class DateFieldStack implements J > } > }; > > - Mapper<String, StylesheetLink> pathToStylesheetLink = pathToAsset > - .combine(TapestryInternalUtils.assetToStylesheetLink); > + Mapper<String, StylesheetLink> pathToStylesheetLink = > F.combine(pathToAsset, > + TapestryInternalUtils.assetToStylesheetLink); > > javaScriptStack = F > .flow("${tapestry.datepicker}/js/datepicker.js", > "org/apache/tapestry5/corelib/components/datefield.js") > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/AbstractFlow.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/AbstractFlow.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/AbstractFlow.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/AbstractFlow.java > Fri Jan 7 21:31:05 2011 > @@ -1,4 +1,4 @@ > -// Copyright 2010 The Apache Software Foundation > +// Copyright 2010, 2011 The Apache Software Foundation > // > // Licensed under the Apache License, Version 2.0 (the "License"); > // you may not use this file except in compliance with the License. > @@ -170,7 +170,7 @@ abstract class AbstractFlow<T> implement > { > assert predicate != null; > > - return filter(predicate.invert()); > + return filter(F.not(predicate)); > } > > public Flow<T> reverse() > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/F.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/F.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/F.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/F.java > Fri Jan 7 21:31:05 2011 > @@ -125,7 +125,7 @@ public class F > */ > public static <T extends Comparable<T>> Predicate<T> lt(T value) > { > - return gteq(value).invert(); > + return not(gteq(value)); > } > > /** > @@ -134,7 +134,7 @@ public class F > */ > public static <T extends Comparable<T>> Predicate<T> lteq(T value) > { > - return gt(value).invert(); > + return not(gt(value)); > } > > /** > @@ -156,9 +156,7 @@ public class F > */ > public static <T> Predicate<T> notNull() > { > - Predicate<T> isNull = isNull(); > - > - return isNull.invert(); > + return not(isNull()); > } > > /** > @@ -346,7 +344,6 @@ public class F > > Flow<Tuple<A, B>> tuples = F.flow(map.entrySet()).map(new > Mapper<Map.Entry<A, B>, Tuple<A, B>>() > { > - �...@override > public Tuple<A, B> map(Entry<A, B> element) > { > return Tuple.create(element.getKey(), element.getValue()); > @@ -457,7 +454,6 @@ public class F > { > return new Predicate<String>() > { > - �...@override > public boolean accept(String element) > { > return element.regionMatches(ignoreCase, 0, prefix, 0, > prefix.length()); > @@ -490,7 +486,6 @@ public class F > { > return new Predicate<String>() > { > - �...@override > public boolean accept(String element) > { > return element > @@ -533,4 +528,132 @@ public class F > } > }; > } > + > + /** > + * Inverts a predicate. > + * > + * @param <T> > + * @param delegate > + * the predicate to invert > + * @return a new predicate that is inverse to the existing predicate > + * @since 5.3.0 > + */ > + public static <T> Predicate<T> not(final Predicate<? super T> delegate) > + { > + assert delegate != null; > + > + return new Predicate<T>() > + { > + public boolean accept(T element) > + { > + return !delegate.accept(element); > + } > + }; > + } > + > + /** > + * Combines two mappers into a composite mapping from type A to type C > via type B. > + * > + * @param <A> > + * @param <B> > + * @param <C> > + * @param abMapper > + * maps from A to B > + * @param bcMapper > + * maps from B to C > + * @return mapper from A to C > + */ > + public static <A, B, C> Mapper<A, C> combine(final Mapper<A, B> > abMapper, final Mapper<B, C> bcMapper) > + { > + assert abMapper != null; > + assert bcMapper != null; > + > + return new Mapper<A, C>() > + { > + > + public C map(A aElement) > + { > + B bElement = abMapper.map(aElement); > + > + return bcMapper.map(bElement); > + } > + > + }; > + } > + > + /** > + * Combines any number of delegates as a logical and operation. > Evaluation terminates > + * with the first delegate predicate that returns false. > + * > + * @param <T> > + * @param delegates > + * to evaluate > + * @return combined delegate > + * @since 5.3.0 > + */ > + public static <T> Predicate<T> and(final Predicate<? super T>... > delegates) > + { > + return new Predicate<T>() > + { > + public boolean accept(T element) > + { > + for (Predicate<? super T> delegate : delegates) > + { > + if (!delegate.accept(element)) > + return false; > + } > + > + return true; > + } > + }; > + } > + > + /** > + * Combines any number of delegates as a logical or operation. > Evaluation terminates > + * with the first delegate predicate that returns true. > + * > + * @param <T> > + * @param delegates > + * to evaluate > + * @return combined delegate > + * @since 5.3.0 > + */ > + public static <T> Predicate<T> or(final Predicate<? super T>... > delegates) > + { > + return new Predicate<T>() > + { > + public boolean accept(T element) > + { > + for (Predicate<? super T> delegate : delegates) > + { > + if (delegate.accept(element)) > + return true; > + } > + > + return false; > + } > + }; > + } > + > + /** > + * Combines several compatible workers together into a composite. > + * > + * @since 5.3.0 > + */ > + public static <T> Worker<T> combine(final Worker<? super T>... delegates) > + { > + assert delegates.length > 0; > + > + return new Worker<T>() > + { > + public void work(T value) > + { > + for (Worker<? super T> delegate : delegates) > + { > + delegate.work(value); > + } > + } > + }; > + } > + > } > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper.java > Fri Jan 7 21:31:05 2011 > @@ -15,9 +15,10 @@ > package org.apache.tapestry5.func; > > /** > - * Base class used with {...@link Flow#map(Mapper)} to > - * define how Flow values are mapped from one type > + * Interface for operation {...@link Flow#map(Mapper)} to define how Flow > elements are mapped from one type > * to another (or otherwise transformed). > + * <p> > + * This changed in 5.3 from an abstract base class to an interface. > * > * @since 5.2.0 > * @param <S> > @@ -25,32 +26,11 @@ package org.apache.tapestry5.func; > * @param <T> > * type of target (output) flow > */ > -public abstract class Mapper<S, T> > +public interface Mapper<S, T> > { > /** > * Implemented in subclasses to map an element from the source flow to an > element of the target > * flow. > */ > - public abstract T map(S element); > - > - /** > - * Combines this mapper (S -->T) with another mapper (T -->X) to > form > - * a composite mapper (S --> X). > - */ > - public final <X> Mapper<S, X> combine(final Mapper<T, X> other) > - { > - assert other != null; > - > - final Mapper<S, T> stMapper = this; > - > - return new Mapper<S, X>() > - { > - public X map(S element) > - { > - T tElement = stMapper.map(element); > - > - return other.map(tElement); > - } > - }; > - } > + T map(S element); > } > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper2.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper2.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper2.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Mapper2.java > Fri Jan 7 21:31:05 2011 > @@ -1,4 +1,4 @@ > -// Copyright 2010 The Apache Software Foundation > +// Copyright 2010, 2011 The Apache Software Foundation > // > // Licensed under the Apache License, Version 2.0 (the "License"); > // you may not use this file except in compliance with the License. > @@ -16,12 +16,14 @@ package org.apache.tapestry5.func; > > /** > * A generalization of {...@link Mapper} for a two-input function. > + * <p> > + * This was converted from to an interface from an abstract base class in > 5.3. > */ > -public abstract class Mapper2<A, B, C> > +public interface Mapper2<A, B, C> > { > /** > * Take, as input, two values (from two flows) and return a computed > value of > * the third type. > */ > - public abstract C map(A first, B second); > + C map(A first, B second); > } > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Predicate.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Predicate.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Predicate.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Predicate.java > Fri Jan 7 21:31:05 2011 > @@ -19,12 +19,14 @@ package org.apache.tapestry5.func; > * each object in turn, and returns true to include the object in the result > collection. > * <p> > * The {...@link F} class includes a number of Predicate factory methods. > + * <p> > + * This was converted from a abstract base class to an interface in 5.3. > * > * @since 5.2.0 > * @see Flow#filter(Predicate) > * @see Flow#remove(Predicate) > */ > -public abstract class Predicate<T> > +public interface Predicate<T> > { > /** > * This method is overridden in subclasses to define which objects the > Predicate will accept > @@ -33,62 +35,5 @@ public abstract class Predicate<T> > * @param element > * the element from the flow to be evaluated by the Predicate > */ > - public abstract boolean accept(T element); > - > - /** > - * Combines this Predicate with another compatible Predicate to form a > new Predicate, which is > - * returned. The new Predicate is true only if both of the combined > Predicates are true. > - */ > - public final Predicate<T> and(final Predicate<? super T> other) > - { > - assert other != null; > - > - final Predicate<T> left = this; > - > - return new Predicate<T>() > - { > - public boolean accept(T object) > - { > - return left.accept(object) && other.accept(object); > - }; > - }; > - } > - > - /** > - * Combines this Predicate with another compatible Predicate to form a > new Predicate, which is > - * returned. The > - * new Predicate is true if either of the combined Predicates are true. > - */ > - public final Predicate<T> or(final Predicate<? super T> other) > - { > - assert other != null; > - > - final Predicate<T> left = this; > - > - return new Predicate<T>() > - { > - public boolean accept(T object) > - { > - return left.accept(object) || other.accept(object); > - }; > - }; > - } > - > - /** > - * Inverts this Predicate, returning a new Predicate that inverts the > value returned from > - * {...@link #accept}. > - */ > - public final Predicate<T> invert() > - { > - final Predicate<T> normal = this; > - > - return new Predicate<T>() > - { > - public boolean accept(T object) > - { > - return !normal.accept(object); > - }; > - }; > - } > - > + boolean accept(T element); > } > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Worker.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Worker.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Worker.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/Worker.java > Fri Jan 7 21:31:05 2011 > @@ -1,4 +1,4 @@ > -// Copyright 2010 The Apache Software Foundation > +// Copyright 2010, 2011 The Apache Software Foundation > // > // Licensed under the Apache License, Version 2.0 (the "License"); > // you may not use this file except in compliance with the License. > @@ -20,32 +20,10 @@ package org.apache.tapestry5.func; > * @since 5.2.0 > * @see Flow#each(Worker) > */ > -public abstract class Worker<T> > +public interface Worker<T> > { > /** > * Perform the operation on some object of type T. > */ > - public abstract void work(T value); > - > - /** > - * Combines this worker with the other worker, forming a new composite > worker. In the composite, > - * the value from the Flow is passed first to this worker, then to the > other worker. > - */ > - public Worker<T> combine(final Worker<? super T> other) > - { > - assert other != null; > - > - final Worker<T> first = this; > - > - return new Worker<T>() > - { > - public void work(T value) > - { > - first.work(value); > - other.work(value); > - } > - > - }; > - } > - > + void work(T value); > } > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/ZippedFlowImpl.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/ZippedFlowImpl.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/ZippedFlowImpl.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/main/java/org/apache/tapestry5/func/ZippedFlowImpl.java > Fri Jan 7 21:31:05 2011 > @@ -143,7 +143,6 @@ class ZippedFlowImpl<A, B> implements Zi > { > return tupleFlow.map(new Mapper<Tuple<A, B>, A>() > { > - �...@override > public A map(Tuple<A, B> value) > { > return value.first; > @@ -160,7 +159,6 @@ class ZippedFlowImpl<A, B> implements Zi > { > return tupleFlow.map(new Mapper<Tuple<A, B>, B>() > { > - �...@override > public B map(Tuple<A, B> value) > { > return value.second; > @@ -174,7 +172,6 @@ class ZippedFlowImpl<A, B> implements Zi > > return filter(new Predicate<Tuple<A, B>>() > { > - �...@override > public boolean accept(Tuple<A, B> element) > { > return predicate.accept(element.first); > @@ -188,7 +185,6 @@ class ZippedFlowImpl<A, B> implements Zi > > return filter(new Predicate<Tuple<A, B>>() > { > - �...@override > public boolean accept(Tuple<A, B> element) > { > return predicate.accept(element.second); > @@ -200,14 +196,14 @@ class ZippedFlowImpl<A, B> implements Zi > { > assert predicate != null; > > - return filterOnFirst(predicate.invert()); > + return filterOnFirst(F.not(predicate)); > } > > public ZippedFlow<A, B> removeOnSecond(Predicate<? super B> predicate) > { > assert predicate != null; > > - return filterOnSecond(predicate.invert()); > + return filterOnSecond(F.not(predicate)); > } > > public Map<A, B> toMap() > @@ -216,7 +212,6 @@ class ZippedFlowImpl<A, B> implements Zi > > tupleFlow.each(new Worker<Tuple<A, B>>() > { > - �...@override > public void work(Tuple<A, B> value) > { > result.put(value.first, value.second); > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java > Fri Jan 7 21:31:05 2011 > @@ -35,7 +35,8 @@ public class FuncTest extends BaseFuncTe > @Test > public void combine_mappers() > { > - List<Boolean> even = F.flow("Mary", "had", "a", "little", > "lamb").map(stringToLength.combine(toEven)).toList(); > + List<Boolean> even = F.flow("Mary", "had", "a", "little", > "lamb").map(F.combine(stringToLength, toEven)) > + .toList(); > > assertListsEquals(even, true, false, false, true, true); > } > @@ -151,7 +152,7 @@ public class FuncTest extends BaseFuncTe > } > }; > > - F.flow("Mary", "had", "a", "little", > "lamb").each(appendWorker.combine(appendLength)); > + 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)"); > } > @@ -205,7 +206,7 @@ public class FuncTest extends BaseFuncTe > { > List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); > > - List<Integer> output = > F.flow(input).filter(F.gt(2).and(F.lt(5))).toList(); > + List<Integer> output = F.flow(input).filter(F.and(F.gt(2), > F.lt(5))).toList(); > > assertListsEquals(output, 3, 4); > } > @@ -215,7 +216,7 @@ public class FuncTest extends BaseFuncTe > { > List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7); > > - List<Integer> output = > F.flow(input).filter(F.lt(3).or(F.gt(5))).toList(); > + List<Integer> output = F.flow(input).filter(F.or(F.lt(3), > F.gt(5))).toList(); > > assertListsEquals(output, 1, 2, 6, 7); > } > @@ -245,7 +246,7 @@ public class FuncTest extends BaseFuncTe > @Test > public void select_and_filter() > { > - Predicate<String> combinedp = > F.toPredicate(stringToLength.combine(toEven)); > + Predicate<String> combinedp = > F.toPredicate(F.combine(stringToLength, toEven)); > > Mapper<String, String> identity = F.identity(); > Predicate<String> isNull = F.isNull(); > > Modified: > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java > Fri Jan 7 21:31:05 2011 > @@ -156,7 +156,6 @@ public class ZippedFlowTests extends Bas > > zipped.each(new Worker<Tuple<Integer, String>>() > { > - �...@override > public void work(Tuple<Integer, String> value) > { > count.addAndGet(value.second.length()); > @@ -220,8 +219,6 @@ public class ZippedFlowTests extends Bas > { > Tuple<String, String> firstTuple = zipped.mapTuples(new > Mapper<Tuple<Integer, String>, Tuple<String, String>>() > { > - > - �...@override > public Tuple<String, String> map(Tuple<Integer, String> value) > { > return Tuple.create(StringUtils.reverse(value.second), > > Modified: > tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=1056524&r1=1056523&r2=1056524&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java > Fri Jan 7 21:31:05 2011 > @@ -277,14 +277,14 @@ public class RegistryImpl implements Reg > contributionMarkers.remove(Local.class); > > // Match services with the correct interface AND having as markers > *all* the marker annotations > - > - Flow<ServiceDef2> filtered = serviceDefs.filter(new > Predicate<ServiceDef2>() > + > + Flow<ServiceDef2> filtered = serviceDefs.filter(F.and(new > Predicate<ServiceDef2>() > { > public boolean accept(ServiceDef2 object) > { > return > object.getServiceInterface().equals(cd.getServiceInterface()); > } > - }.and(new Predicate<ServiceDef2>() > + }, new Predicate<ServiceDef2>() > { > public boolean accept(ServiceDef2 serviceDef) > { > @@ -1001,7 +1001,7 @@ public class RegistryImpl implements Reg > { > assert interfaceClass != null; > assert implementationClass != null; > - > + > if (InternalUtils.SERVICE_CLASS_RELOADING_ENABLED && > InternalUtils.isLocalFile(implementationClass)) > return createReloadingProxy(interfaceClass, implementationClass, > locator); > > > >
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
