Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 58130 invoked from network); 4 Apr 2008 23:09:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Apr 2008 23:09:13 -0000 Received: (qmail 95355 invoked by uid 500); 4 Apr 2008 23:09:13 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 95294 invoked by uid 500); 4 Apr 2008 23:09:12 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 95285 invoked by uid 99); 4 Apr 2008 23:09:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 16:09:12 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 23:08:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5BCC51A983A; Fri, 4 Apr 2008 16:08:36 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r644988 [2/2] - in /commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor: adapter/ core/ core/collection/ core/comparator/ core/composite/ generator/util/ Date: Fri, 04 Apr 2008 23:08:27 -0000 To: commits@commons.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080404230842.5BCC51A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java?rev=644988&r1=644987&r2=644988&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java (original) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java Fri Apr 4 16:08:18 2008 @@ -41,10 +41,20 @@ * @author Rodney Waldhoff */ public final class ConditionalPredicate implements Predicate, Serializable { + // attributes + // ------------------------------------------------------------------------ + private Predicate ifPred = null; + private Predicate thenPred = null; + private Predicate elsePred = null; // constructor // ------------------------------------------------------------------------ - + /** + * Create a new ConditionalPredicate. + * @param ifPred if + * @param thenPred then + * @param elsePred else + */ public ConditionalPredicate(Predicate ifPred, Predicate thenPred, Predicate elsePred) { this.ifPred = ifPred; this.thenPred = thenPred; @@ -53,10 +63,16 @@ // predicate interface // ------------------------------------------------------------------------ + /** + * {@inheritDoc} + */ public boolean test() { return ifPred.test() ? thenPred.test() : elsePred.test(); } + /** + * {@inheritDoc} + */ public boolean equals(Object that) { if (that instanceof ConditionalPredicate) { return equals((ConditionalPredicate) that); @@ -65,13 +81,21 @@ } } + /** + * Learn whether another ConditionalPredicate is equal to this. + * @param that ConditionalPredicate to test + * @return boolean + */ public boolean equals(ConditionalPredicate that) { - return null != that && - (null == ifPred ? null == that.ifPred : ifPred.equals(that.ifPred)) && - (null == thenPred ? null == that.thenPred : thenPred.equals(that.thenPred)) && - (null == elsePred ? null == that.elsePred : elsePred.equals(that.elsePred)); + return null != that + && (null == ifPred ? null == that.ifPred : ifPred.equals(that.ifPred)) + && (null == thenPred ? null == that.thenPred : thenPred.equals(that.thenPred)) + && (null == elsePred ? null == that.elsePred : elsePred.equals(that.elsePred)); } + /** + * {@inheritDoc} + */ public int hashCode() { int hash = "ConditionalPredicate".hashCode(); if (null != ifPred) { @@ -89,13 +113,11 @@ return hash; } + /** + * {@inheritDoc} + */ public String toString() { return "ConditionalPredicate<" + ifPred + "?" + thenPred + ":" + elsePred + ">"; } - // attributes - // ------------------------------------------------------------------------ - private Predicate ifPred = null; - private Predicate thenPred = null; - private Predicate elsePred = null; } Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java?rev=644988&r1=644987&r2=644988&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java (original) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java Fri Apr 4 16:08:18 2008 @@ -41,10 +41,20 @@ * @author Rodney Waldhoff */ public final class ConditionalUnaryPredicate implements UnaryPredicate, Serializable { + // attributes + // ------------------------------------------------------------------------ + private UnaryPredicate ifPred = null; + private UnaryPredicate thenPred = null; + private UnaryPredicate elsePred = null; // constructor // ------------------------------------------------------------------------ - + /** + * Create a new ConditionalUnaryPredicate. + * @param ifPred if + * @param thenPred then + * @param elsePred else + */ public ConditionalUnaryPredicate(UnaryPredicate ifPred, UnaryPredicate thenPred, UnaryPredicate elsePred) { this.ifPred = ifPred; this.thenPred = thenPred; @@ -53,10 +63,16 @@ // predicate interface // ------------------------------------------------------------------------ + /** + * {@inheritDoc} + */ public boolean test(Object obj) { return ifPred.test(obj) ? thenPred.test(obj) : elsePred.test(obj); } + /** + * {@inheritDoc} + */ public boolean equals(Object that) { if (that instanceof ConditionalUnaryPredicate) { return equals((ConditionalUnaryPredicate) that); @@ -65,13 +81,21 @@ } } + /** + * Learn whether another ConditionalUnaryPredicate is equal to this. + * @param that ConditionalUnaryPredicate to test + * @return boolean + */ public boolean equals(ConditionalUnaryPredicate that) { - return null != that && - (null == ifPred ? null == that.ifPred : ifPred.equals(that.ifPred)) && - (null == thenPred ? null == that.thenPred : thenPred.equals(that.thenPred)) && - (null == elsePred ? null == that.elsePred : elsePred.equals(that.elsePred)); + return null != that + && (null == ifPred ? null == that.ifPred : ifPred.equals(that.ifPred)) + && (null == thenPred ? null == that.thenPred : thenPred.equals(that.thenPred)) + && (null == elsePred ? null == that.elsePred : elsePred.equals(that.elsePred)); } + /** + * {@inheritDoc} + */ public int hashCode() { int hash = "ConditionalUnaryPredicate".hashCode(); if (null != ifPred) { @@ -89,13 +113,11 @@ return hash; } + /** + * {@inheritDoc} + */ public String toString() { return "ConditionalUnaryPredicate<" + ifPred + "?" + thenPred + ":" + elsePred + ">"; } - // attributes - // ------------------------------------------------------------------------ - private UnaryPredicate ifPred = null; - private UnaryPredicate thenPred = null; - private UnaryPredicate elsePred = null; } Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java?rev=644988&r1=644987&r2=644988&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java (original) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java Fri Apr 4 16:08:18 2008 @@ -39,8 +39,8 @@ public class DoWhileProcedure extends AbstractLoopProcedure { /** * Create a new DoWhileProcedure. - * @param action - * @param condition + * @param action to do + * @param condition while true */ public DoWhileProcedure(Procedure action, Predicate condition) { super(condition, action); @@ -60,9 +60,9 @@ */ public boolean equals(Object object) { if (object instanceof DoWhileProcedure) { - return super.equals(object); + return super.equals(object); } else { - return false; + return false; } } @@ -70,7 +70,7 @@ * {@inheritDoc} */ public int hashCode() { - return super.hashCode("DoWhileProcedure".hashCode()); + return super.hashCode("DoWhileProcedure".hashCode()); } /** Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Not.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Not.java?rev=644988&r1=644987&r2=644988&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Not.java (original) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Not.java Fri Apr 4 16:08:18 2008 @@ -35,30 +35,33 @@ * @author Rodney Waldhoff */ public final class Not implements Predicate, Serializable { - - // static - // ------------------------------------------------------------------------ - public static Predicate not(Predicate that) { - return null == that ? null : new Not(that); - } - + // attributes // ------------------------------------------------------------------------ private Predicate predicate = null; // constructor // ------------------------------------------------------------------------ - + /** + * Create a new Not. + * @param p Predicate to negate + */ public Not(Predicate p) { this.predicate = p; } // predicate interface // ------------------------------------------------------------------------ + /** + * {@inheritDoc} + */ public boolean test() { return !(predicate.test()); } + /** + * {@inheritDoc} + */ public boolean equals(Object that) { if (that instanceof Not) { return equals((Not) that); @@ -67,10 +70,18 @@ } } + /** + * Learn whether another Not is equal to this. + * @param that the Not to test + * @return boolean + */ public boolean equals(Not that) { return null != that && (null == predicate ? null == that.predicate : predicate.equals(that.predicate)); } + /** + * {@inheritDoc} + */ public int hashCode() { int hash = "Not".hashCode(); if (null != predicate) { @@ -79,7 +90,21 @@ return hash; } + /** + * {@inheritDoc} + */ public String toString() { return "Not<" + predicate + ">"; + } + + // static + // ------------------------------------------------------------------------ + /** + * Get a Not instance for that. + * @param that Predicate to negate + * @return Not + */ + public static Predicate not(Predicate that) { + return null == that ? null : new Not(that); } } Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Sequence.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Sequence.java?rev=644988&r1=644987&r2=644988&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Sequence.java (original) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Sequence.java Fri Apr 4 16:08:18 2008 @@ -42,15 +42,31 @@ */ public class Sequence implements Procedure, Serializable { + // attributes + // ------------------------------------------------------------------------ + private List list = new ArrayList(); + // constructor // ------------------------------------------------------------------------ + /** + * Create a new Sequence. + */ public Sequence() { } + /** + * Create a new Sequence. + * @param p Procedure to add + */ public Sequence(Procedure p) { then(p); } + /** + * Create a new Sequence. + * @param p Procedure to add + * @param q Procedure to add + */ public Sequence(Procedure p, Procedure q) { then(p); then(q); @@ -58,6 +74,11 @@ // modifiers // ------------------------------------------------------------------------ + /** + * Fluently add a Procedure. + * @param p Procedure to add + * @return this + */ public Sequence then(Procedure p) { list.add(p); return this; @@ -65,12 +86,18 @@ // predicate interface // ------------------------------------------------------------------------ + /** + * {@inheritDoc} + */ public void run() { for (ListIterator iter = list.listIterator(list.size()); iter.hasPrevious();) { ((Procedure) iter.previous()).run(); } } + /** + * {@inheritDoc} + */ public boolean equals(Object that) { if (that instanceof Sequence) { return equals((Sequence) that); @@ -79,23 +106,29 @@ } } + /** + * Learn whether a given Sequence is equal to this. + * @param that Sequence to test + * @return boolean + */ public boolean equals(Sequence that) { // by construction, list is never null return null != that && list.equals(that.list); } + /** + * {@inheritDoc} + */ public int hashCode() { // by construction, list is never null return "Sequence".hashCode() ^ list.hashCode(); } + /** + * {@inheritDoc} + */ public String toString() { return "Sequence<" + list + ">"; } - - - // attributes - // ------------------------------------------------------------------------ - private List list = new ArrayList(); } Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/EachElement.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/EachElement.java?rev=644988&r1=644987&r2=644988&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/EachElement.java (original) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/EachElement.java Fri Apr 4 16:08:18 2008 @@ -25,14 +25,18 @@ import org.apache.commons.functor.generator.IteratorToGeneratorAdapter; /** - * Generator for each element of a collection. + * Generator factory for each element of a "collection". * * @since 1.0 * @version $Revision$ $Date$ * @author Jason Horman (jason@jhorman.org) */ - public final class EachElement { + /** + * Get a Generator for each element of a Collection. + * @param collection to iterate + * @return Generator + */ public static final Generator from(Collection collection) { if (null == collection) { return null; @@ -41,6 +45,11 @@ } } + /** + * Get a Generator for each entry of a Map. + * @param map to iterate + * @return Generator + */ public static final Generator from(Map map) { if (null == map) { return null; @@ -49,6 +58,11 @@ } } + /** + * Get a Generator for each element of an Object[]. + * @param array to iterate + * @return Generator + */ public static final Generator from(Object[] array) { if (null == array) { return null; @@ -57,6 +71,11 @@ } } + /** + * Get a Generator for each element of an Iterator. + * @param iter to iterate + * @return Generator + */ public static final Generator from(Iterator iter) { if (null == iter) { return null;