You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2003/02/19 01:54:37 UTC
cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection TestAll.java TestCollectionAlgorithms.java
rwaldhoff 2003/02/18 16:54:37
Modified: functor/src/java/org/apache/commons/functor/adapter
BoundFunction.java BoundPredicate.java
BoundProcedure.java LeftBoundFunction.java
LeftBoundPredicate.java LeftBoundProcedure.java
RightBoundFunction.java RightBoundPredicate.java
RightBoundProcedure.java
functor/src/test/org/apache/commons/functor/adapter
TestBoundFunction.java TestBoundPredicate.java
TestBoundProcedure.java TestLeftBoundFunction.java
TestLeftBoundPredicate.java
TestLeftBoundProcedure.java
TestRightBoundFunction.java
TestRightBoundPredicate.java
TestRightBoundProcedure.java
functor/src/test/org/apache/commons/functor/core
TestAll.java
Added: functor/src/java/org/apache/commons/functor/core/collection
CollectionAlgorithms.java package.html
functor/src/test/org/apache/commons/functor/core/collection
TestAll.java TestCollectionAlgorithms.java
Log:
* rename *Bound*.adapt() to bind()
* add collection based algorithms and test
Revision Changes Path
1.3 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/BoundFunction.java
Index: BoundFunction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/BoundFunction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BoundFunction.java 18 Feb 2003 20:35:40 -0000 1.2
+++ BoundFunction.java 19 Feb 2003 00:54:35 -0000 1.3
@@ -141,7 +141,7 @@
* {@link UnaryFunction UnaryFunction}, or <code>null</code>
* if the given <code>UnaryFunction</code> is <code>null</code>
*/
- public static BoundFunction adapt(UnaryFunction function, Object arg) {
+ public static BoundFunction bind(UnaryFunction function, Object arg) {
return null == function ? null : new BoundFunction(function,arg);
}
1.3 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/BoundPredicate.java
Index: BoundPredicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/BoundPredicate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BoundPredicate.java 18 Feb 2003 20:35:40 -0000 1.2
+++ BoundPredicate.java 19 Feb 2003 00:54:35 -0000 1.3
@@ -141,7 +141,7 @@
* {@link UnaryPredicate UnaryPredicate}, or <code>null</code>
* if the given <code>UnaryPredicate</code> is <code>null</code>
*/
- public static BoundPredicate adapt(UnaryPredicate predicate, Object arg) {
+ public static BoundPredicate bind(UnaryPredicate predicate, Object arg) {
return null == predicate ? null : new BoundPredicate(predicate,arg);
}
1.3 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/BoundProcedure.java
Index: BoundProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/BoundProcedure.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BoundProcedure.java 18 Feb 2003 20:35:40 -0000 1.2
+++ BoundProcedure.java 19 Feb 2003 00:54:35 -0000 1.3
@@ -141,7 +141,7 @@
* {@link UnaryProcedure UnaryProcedure}, or <code>null</code>
* if the given <code>UnaryProcedure</code> is <code>null</code>
*/
- public static BoundProcedure adapt(UnaryProcedure procedure, Object arg) {
+ public static BoundProcedure bind(UnaryProcedure procedure, Object arg) {
return null == procedure ? null : new BoundProcedure(procedure,arg);
}
1.2 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
Index: LeftBoundFunction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/LeftBoundFunction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LeftBoundFunction.java 28 Jan 2003 23:37:49 -0000 1.1
+++ LeftBoundFunction.java 19 Feb 2003 00:54:35 -0000 1.2
@@ -125,7 +125,7 @@
return "LeftBoundFunction<" + function + "(" + param + ",?)>";
}
- public static LeftBoundFunction adapt(BinaryFunction function, Object arg) {
+ public static LeftBoundFunction bind(BinaryFunction function, Object arg) {
return null == function ? null : new LeftBoundFunction(function,arg);
}
1.2 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
Index: LeftBoundPredicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LeftBoundPredicate.java 28 Jan 2003 23:37:49 -0000 1.1
+++ LeftBoundPredicate.java 19 Feb 2003 00:54:35 -0000 1.2
@@ -125,7 +125,7 @@
return "LeftBoundPredicate<" + predicate + "(" + param + ",?)>";
}
- public static LeftBoundPredicate adapt(BinaryPredicate predicate, Object arg) {
+ public static LeftBoundPredicate bind(BinaryPredicate predicate, Object arg) {
return null == predicate ? null : new LeftBoundPredicate(predicate,arg);
}
1.2 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
Index: LeftBoundProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LeftBoundProcedure.java 28 Jan 2003 23:37:49 -0000 1.1
+++ LeftBoundProcedure.java 19 Feb 2003 00:54:35 -0000 1.2
@@ -125,7 +125,7 @@
return "LeftBoundProcedure<" + procedure + "(" + param + ",?)>";
}
- public static LeftBoundProcedure adapt(BinaryProcedure procedure, Object arg) {
+ public static LeftBoundProcedure bind(BinaryProcedure procedure, Object arg) {
return null == procedure ? null : new LeftBoundProcedure(procedure,arg);
}
1.2 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/RightBoundFunction.java
Index: RightBoundFunction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/RightBoundFunction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RightBoundFunction.java 28 Jan 2003 23:37:49 -0000 1.1
+++ RightBoundFunction.java 19 Feb 2003 00:54:35 -0000 1.2
@@ -125,7 +125,7 @@
return "RightBoundFunction<" + function + "(?," + param + ")>";
}
- public static RightBoundFunction adapt(BinaryFunction function, Object arg) {
+ public static RightBoundFunction bind(BinaryFunction function, Object arg) {
return null == function ? null : new RightBoundFunction(function,arg);
}
1.2 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
Index: RightBoundPredicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/RightBoundPredicate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RightBoundPredicate.java 28 Jan 2003 23:37:49 -0000 1.1
+++ RightBoundPredicate.java 19 Feb 2003 00:54:35 -0000 1.2
@@ -125,7 +125,7 @@
return "RightBoundPredicate<" + predicate + "(?," + param + ")>";
}
- public static RightBoundPredicate adapt(BinaryPredicate predicate, Object arg) {
+ public static RightBoundPredicate bind(BinaryPredicate predicate, Object arg) {
return null == predicate ? null : new RightBoundPredicate(predicate,arg);
}
1.2 +3 -3 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
Index: RightBoundProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/RightBoundProcedure.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RightBoundProcedure.java 28 Jan 2003 23:37:49 -0000 1.1
+++ RightBoundProcedure.java 19 Feb 2003 00:54:35 -0000 1.2
@@ -125,7 +125,7 @@
return "RightBoundProcedure<" + procedure + "(?," + param + ")>";
}
- public static RightBoundProcedure adapt(BinaryProcedure procedure, Object arg) {
+ public static RightBoundProcedure bind(BinaryProcedure procedure, Object arg) {
return null == procedure ? null : new RightBoundProcedure(procedure,arg);
}
1.1 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/collection/CollectionAlgorithms.java
Index: CollectionAlgorithms.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/collection/CollectionAlgorithms.java,v 1.1 2003/02/19 00:54:36 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.functor.core.collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
/**
* @version $Revision: 1.1 $ $Date: 2003/02/19 00:54:36 $
* @author Rodney Waldhoff
*/
public final class CollectionAlgorithms {
// constructor
// ------------------------------------------------------------------------
/**
* Public constructor, for systems that prefer
* instantiable classes (Jelly, Velocity, etc.)
*/
public CollectionAlgorithms() {
}
// static methods
// ------------------------------------------------------------------------
/**
* {@link UnaryFunction#evaluate Apply} the given
* {@link UnaryFunction UnaryFunction} to
* each element in the given {@link Iterator Iterator},
* and {@link Collection#add add} the result to a
* new {@link Collection}.
*
* @see #collect(java.util.Iterator,org.apache.commons.functor.UnaryFunction,java.util.Collection}
*/
public static Collection collect(Iterator iter, UnaryFunction func) {
return collect(iter,func,new ArrayList());
}
/**
* {@link UnaryFunction#evaluate Apply} the given
* {@link UnaryFunction UnaryFunction} to
* each element in the given {@link Iterator Iterator},
* and {@link Collection#add add} the result to the
* given {@link Collection}.
*
* @return the given {@link Collection}
* @see #collect(java.util.Iterator,org.apache.commons.functor.UnaryFunction}
*/
public static Collection collect(Iterator iter, UnaryFunction func, Collection col) {
while(iter.hasNext()) {
col.add(func.evaluate(iter.next()));
}
return col;
}
/**
* Return <code>true</code> iff some element in
* the given
* {@link Iterator Iterator} that matches the given
* {@link UnaryPredicate UnaryPredicate}.
*
* @see #detect(java.util.Iterator,org.apache.commons.functor.UnaryPredicate}
*/
public static boolean contains(Iterator iter, UnaryPredicate pred) {
while(iter.hasNext()) {
if(pred.test(iter.next())) {
return true;
}
}
return false;
}
/**
* Return the first element within the given
* {@link Iterator Iterator} that matches the given
* {@link UnaryPredicate UnaryPredicate}, or throw
* {@link NoSuchElementException NoSuchElementException} if no
* matching element can be found.
*
* @see #detect(java.util.Iterator,org.apache.commons.functor.UnaryPredicate,java.lang.Object}
*/
public static Object detect(Iterator iter, UnaryPredicate pred) {
while(iter.hasNext()) {
Object obj = iter.next();
if(pred.test(obj)) {
return obj;
}
}
throw new NoSuchElementException("No element matching " + pred + " was found.");
}
/**
* Return the first element within the given
* {@link Iterator Iterator} that matches the given
* {@link UnaryPredicate UnaryPredicate}, or return
* the given (possibly <code>null</code> <code>Object</code>
* if no matching element can be found.
*
* @see #detect(java.util.Iterator,org.apache.commons.functor.UnaryPredicate}
*/
public static Object detect(Iterator iter, UnaryPredicate pred, Object ifNone) {
while(iter.hasNext()) {
Object obj = iter.next();
if(pred.test(obj)) {
return obj;
}
}
return ifNone;
}
/**
* {@link UnaryProcedure#run Apply} the given
* {@link UnaryProcedure UnaryProcedure}
* to each element in the given {@link Iterator Iterator}.
*/
public static void foreach(Iterator iter, UnaryProcedure proc) {
while(iter.hasNext()) {
proc.run(iter.next());
}
}
/**
* {@link Collection#add Add} all elements within the
* given {@link Iterator Iterator} that match the
* given {@link UnaryPredicate UnaryPredicate} to the
* given {@link Collection Collection}.
*
* @return the given {@link Collection Collection}
* @see #select(java.util.Iterator,org.apache.commons.functor.UnaryPredicate)
* @see #reject(java.util.Iterator,org.apache.commons.functor.UnaryPredicate,java.util.Collection)
*/
public static Collection select(Iterator iter, UnaryPredicate pred, Collection col) {
while(iter.hasNext()) {
Object obj = iter.next();
if(pred.test(obj)) {
col.add(obj);
}
}
return col;
}
/**
* {@link Collection#add Add} all elements within the
* given {@link Iterator Iterator} that match the
* given {@link UnaryPredicate UnaryPredicate} to a
* new {@link Collection Collection}.
*
* @return the new {@link Collection Collection}
* @see #select(java.util.Iterator,org.apache.commons.functor.UnaryPredicate,java.util.Collection)
* @see #reject(java.util.Iterator,org.apache.commons.functor.UnaryPredicate)
*/
public static Collection select(Iterator iter, UnaryPredicate pred) {
return select(iter,pred,new ArrayList());
}
/**
* {@link Collection#add Add} all elements within the
* given {@link Iterator Iterator} that fail to match the
* given {@link UnaryPredicate UnaryPredicate} to the
* given {@link Collection Collection}.
*
* @return the given {@link Collection Collection}
* @see #reject(java.util.Iterator,org.apache.commons.functor.UnaryPredicate)
* @see #select(java.util.Iterator,org.apache.commons.functor.UnaryPredicate,java.util.Collection)
*/
public static Collection reject(Iterator iter, UnaryPredicate pred, Collection col) {
while(iter.hasNext()) {
Object obj = iter.next();
if(!pred.test(obj)) {
col.add(obj);
}
}
return col;
}
/**
* {@link Collection#add Add} all elements within the
* given {@link Iterator Iterator} that fail to match the
* given {@link UnaryPredicate UnaryPredicate} to a
* new {@link Collection Collection}.
*
* @return the new {@link Collection Collection}
* @see #reject(java.util.Iterator,org.apache.commons.functor.UnaryPredicate,java.util.Collection)
* @see #select(java.util.Iterator,org.apache.commons.functor.UnaryPredicate)
*/
public static Collection reject(Iterator iter, UnaryPredicate pred) {
return reject(iter,pred,new ArrayList());
}
}
1.1 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/collection/package.html
Index: package.html
===================================================================
<!--
$Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/collection/package.html,v 1.1 2003/02/19 00:54:36 rwaldhoff Exp $
====================================================================
The Apache Software License, Version 1.1
Copyright (c) 2003 The Apache Software Foundation. All rights
reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed by the
Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "The Jakarta Project", "Commons", and "Apache Software
Foundation" must not be used to endorse or promote products derived
from this software without prior written permission. For written
permission, please contact apache@apache.org.
5. Products derived from this software may not be called "Apache",
nor may "Apache" appear in their name, without prior written
permission of the Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
This software consists of voluntary contributions made by many
individuals on behalf of the Apache Software Foundation. For more
information on the Apache Software Foundation, please see
<http://www.apache.org/>.
-->
<html><body>
<p>
{@link java.util.Collection Collection}-based functors, algorithms and utilities.
</p>
</body></html>
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestBoundFunction.java
Index: TestBoundFunction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestBoundFunction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestBoundFunction.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestBoundFunction.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -121,11 +121,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(BoundFunction.adapt(null,"xyzzy"));
+ assertNull(BoundFunction.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(BoundFunction.adapt(new IdentityFunction(),"xyzzy"));
- assertNotNull(BoundFunction.adapt(new IdentityFunction(),null));
+ assertNotNull(BoundFunction.bind(new IdentityFunction(),"xyzzy"));
+ assertNotNull(BoundFunction.bind(new IdentityFunction(),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestBoundPredicate.java
Index: TestBoundPredicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestBoundPredicate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestBoundPredicate.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestBoundPredicate.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -126,11 +126,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(BoundPredicate.adapt(null,"xyzzy"));
+ assertNull(BoundPredicate.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(BoundPredicate.adapt(new ConstantPredicate(true),"xyzzy"));
- assertNotNull(BoundPredicate.adapt(new ConstantPredicate(true),null));
+ assertNotNull(BoundPredicate.bind(new ConstantPredicate(true),"xyzzy"));
+ assertNotNull(BoundPredicate.bind(new ConstantPredicate(true),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestBoundProcedure.java
Index: TestBoundProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestBoundProcedure.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestBoundProcedure.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestBoundProcedure.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -120,11 +120,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(BoundProcedure.adapt(null,"xyzzy"));
+ assertNull(BoundProcedure.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(BoundProcedure.adapt(new NoOpProcedure(),"xyzzy"));
- assertNotNull(BoundProcedure.adapt(new NoOpProcedure(),null));
+ assertNotNull(BoundProcedure.bind(new NoOpProcedure(),"xyzzy"));
+ assertNotNull(BoundProcedure.bind(new NoOpProcedure(),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestLeftBoundFunction.java
Index: TestLeftBoundFunction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestLeftBoundFunction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestLeftBoundFunction.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestLeftBoundFunction.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -122,11 +122,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(LeftBoundFunction.adapt(null,"xyzzy"));
+ assertNull(LeftBoundFunction.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(LeftBoundFunction.adapt(new RightIdentityFunction(),"xyzzy"));
- assertNotNull(LeftBoundFunction.adapt(new RightIdentityFunction(),null));
+ assertNotNull(LeftBoundFunction.bind(new RightIdentityFunction(),"xyzzy"));
+ assertNotNull(LeftBoundFunction.bind(new RightIdentityFunction(),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestLeftBoundPredicate.java
Index: TestLeftBoundPredicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestLeftBoundPredicate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestLeftBoundPredicate.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestLeftBoundPredicate.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -123,11 +123,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(LeftBoundPredicate.adapt(null,"xyzzy"));
+ assertNull(LeftBoundPredicate.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(LeftBoundPredicate.adapt(new ConstantPredicate(false),"xyzzy"));
- assertNotNull(LeftBoundPredicate.adapt(new ConstantPredicate(false),null));
+ assertNotNull(LeftBoundPredicate.bind(new ConstantPredicate(false),"xyzzy"));
+ assertNotNull(LeftBoundPredicate.bind(new ConstantPredicate(false),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestLeftBoundProcedure.java
Index: TestLeftBoundProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestLeftBoundProcedure.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestLeftBoundProcedure.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestLeftBoundProcedure.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -122,11 +122,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(LeftBoundProcedure.adapt(null,"xyzzy"));
+ assertNull(LeftBoundProcedure.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(LeftBoundProcedure.adapt(new NoOpProcedure(),"xyzzy"));
- assertNotNull(LeftBoundProcedure.adapt(new NoOpProcedure(),null));
+ assertNotNull(LeftBoundProcedure.bind(new NoOpProcedure(),"xyzzy"));
+ assertNotNull(LeftBoundProcedure.bind(new NoOpProcedure(),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestRightBoundFunction.java
Index: TestRightBoundFunction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestRightBoundFunction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRightBoundFunction.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestRightBoundFunction.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -122,11 +122,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(RightBoundFunction.adapt(null,"xyzzy"));
+ assertNull(RightBoundFunction.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(RightBoundFunction.adapt(new LeftIdentityFunction(),"xyzzy"));
- assertNotNull(RightBoundFunction.adapt(new LeftIdentityFunction(),null));
+ assertNotNull(RightBoundFunction.bind(new LeftIdentityFunction(),"xyzzy"));
+ assertNotNull(RightBoundFunction.bind(new LeftIdentityFunction(),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestRightBoundPredicate.java
Index: TestRightBoundPredicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestRightBoundPredicate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRightBoundPredicate.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestRightBoundPredicate.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -123,11 +123,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(RightBoundPredicate.adapt(null,"xyzzy"));
+ assertNull(RightBoundPredicate.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(RightBoundPredicate.adapt(new ConstantPredicate(false),"xyzzy"));
- assertNotNull(RightBoundPredicate.adapt(new ConstantPredicate(false),null));
+ assertNotNull(RightBoundPredicate.bind(new ConstantPredicate(false),"xyzzy"));
+ assertNotNull(RightBoundPredicate.bind(new ConstantPredicate(false),null));
}
}
1.2 +5 -5 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestRightBoundProcedure.java
Index: TestRightBoundProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestRightBoundProcedure.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRightBoundProcedure.java 28 Jan 2003 23:37:50 -0000 1.1
+++ TestRightBoundProcedure.java 19 Feb 2003 00:54:36 -0000 1.2
@@ -122,11 +122,11 @@
}
public void testAdaptNull() throws Exception {
- assertNull(RightBoundProcedure.adapt(null,"xyzzy"));
+ assertNull(RightBoundProcedure.bind(null,"xyzzy"));
}
public void testAdapt() throws Exception {
- assertNotNull(RightBoundProcedure.adapt(new NoOpProcedure(),"xyzzy"));
- assertNotNull(RightBoundProcedure.adapt(new NoOpProcedure(),null));
+ assertNotNull(RightBoundProcedure.bind(new NoOpProcedure(),"xyzzy"));
+ assertNotNull(RightBoundProcedure.bind(new NoOpProcedure(),null));
}
}
1.3 +3 -2 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestAll.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestAll.java 29 Jan 2003 23:03:18 -0000 1.2
+++ TestAll.java 19 Feb 2003 00:54:36 -0000 1.3
@@ -88,6 +88,7 @@
suite.addTest(TestRightIdentityPredicate.suite());
suite.addTest(org.apache.commons.functor.core.composite.TestAll.suite());
+ suite.addTest(org.apache.commons.functor.core.collection.TestAll.suite());
return suite;
}
1.1 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestAll.java
Index: TestAll.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestAll.java,v 1.1 2003/02/19 00:54:37 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.functor.core.collection;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* @version $Revision: 1.1 $ $Date: 2003/02/19 00:54:37 $
* @author Rodney Waldhoff
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestCollectionAlgorithms.suite());
return suite;
}
}
1.1 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestCollectionAlgorithms.java
Index: TestCollectionAlgorithms.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestCollectionAlgorithms.java,v 1.1 2003/02/19 00:54:37 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.functor.core.collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.EqualPredicate;
import org.apache.commons.functor.core.IdentityFunction;
/**
* @version $Revision: 1.1 $ $Date: 2003/02/19 00:54:37 $
* @author Rodney Waldhoff
*/
public class TestCollectionAlgorithms extends TestCase {
// Conventional
// ------------------------------------------------------------------------
public TestCollectionAlgorithms(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestCollectionAlgorithms.class);
}
// Lifecycle
// ------------------------------------------------------------------------
public void setUp() throws Exception {
super.setUp();
list = new ArrayList();
evens = new ArrayList();
listWithDuplicates = new ArrayList();
sum = 0;
for(int i=0;i<10;i++) {
list.add(new Integer(i));
listWithDuplicates.add(new Integer(i));
listWithDuplicates.add(new Integer(i));
sum += i;
if(i%2 == 0) {
evens.add(new Integer(i));
}
}
}
public void tearDown() throws Exception {
super.tearDown();
list = null;
evens = null;
listWithDuplicates = null;
sum = 0;
}
// Tests
// ------------------------------------------------------------------------
public void testHasPublicConstructor() {
// some frameworks work best with instantiable classes
assertNotNull(new CollectionAlgorithms());
}
public void testCollect() {
Collection result = CollectionAlgorithms.collect(list.iterator(),IdentityFunction.getIdentityFunction());
assertNotNull(result);
assertEquals(list.size(),result.size());
assertEquals(list,result);
}
public void testCollect2() {
Set set = new HashSet();
assertSame(set,CollectionAlgorithms.collect(list.iterator(),IdentityFunction.getIdentityFunction(),set));
assertEquals(list.size(),set.size());
for(Iterator iter = list.iterator(); iter.hasNext(); ) {
assertTrue(set.contains(iter.next()));
}
}
public void testCollect3() {
Set set = new HashSet();
assertSame(set,CollectionAlgorithms.collect(listWithDuplicates.iterator(),IdentityFunction.getIdentityFunction(),set));
assertTrue(listWithDuplicates.size() > set.size());
for(Iterator iter = listWithDuplicates.iterator(); iter.hasNext(); ) {
assertTrue(set.contains(iter.next()));
}
}
public void testContains() {
assertTrue(CollectionAlgorithms.contains(list.iterator(),equalsThree));
assertTrue(!CollectionAlgorithms.contains(list.iterator(),equalsTwentyThree));
}
public void testDetect() {
assertEquals(new Integer(3),CollectionAlgorithms.detect(list.iterator(),equalsThree));
try {
CollectionAlgorithms.detect(list.iterator(),equalsTwentyThree);
fail("Expected NoSuchElementException");
} catch(NoSuchElementException e) {
// expected
}
}
public void testDetectIfNone() {
assertEquals(new Integer(3),CollectionAlgorithms.detect(list.iterator(),equalsThree,"Xyzzy"));
assertEquals("Xyzzy",CollectionAlgorithms.detect(list.iterator(),equalsTwentyThree,"Xyzzy"));
}
public void testForEach() {
Summer summer = new Summer();
CollectionAlgorithms.foreach(list.iterator(),summer);
assertEquals(sum,summer.sum);
}
public void testSelect1() {
Collection result = CollectionAlgorithms.select(list.iterator(),isEven);
assertNotNull(result);
assertEquals(evens,result);
}
public void testSelect2() {
ArrayList result = new ArrayList();
assertSame(result,CollectionAlgorithms.select(list.iterator(),isEven,result));
assertEquals(evens,result);
}
public void testReject1() {
Collection result = CollectionAlgorithms.reject(list.iterator(),isOdd);
assertNotNull(result);
assertEquals(evens,result);
}
public void testReject2() {
ArrayList result = new ArrayList();
assertSame(result,CollectionAlgorithms.reject(list.iterator(),isOdd,result));
assertEquals(evens,result);
}
// Attributes
// ------------------------------------------------------------------------
private List list = null;
private List evens = null;
private List listWithDuplicates = null;
private int sum = 0;
private UnaryPredicate equalsThree = LeftBoundPredicate.bind(EqualPredicate.getEqualPredicate(),new Integer(3));
private UnaryPredicate equalsTwentyThree = LeftBoundPredicate.bind(EqualPredicate.getEqualPredicate(),new Integer(23));
private UnaryPredicate isEven = new UnaryPredicate() {
public boolean test(Object obj) {
return ((Number)obj).intValue() % 2 == 0;
}
};
private UnaryPredicate isOdd = new UnaryPredicate() {
public boolean test(Object obj) {
return ((Number)obj).intValue() % 2 != 0;
}
};
// Classes
// ------------------------------------------------------------------------
static class Summer implements UnaryProcedure {
public void run(Object that) {
sum += ((Number)that).intValue();
}
public int sum = 0;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org