You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2012/08/23 05:04:57 UTC
svn commit: r1376354 [1/2] - in
/commons/proper/functor/branches/generators-FUNCTOR-14/src:
main/java/org/apache/commons/functor/core/algorithm/
main/java/org/apache/commons/functor/generator/
main/java/org/apache/commons/functor/generator/loop/ main/j...
Author: kinow
Date: Thu Aug 23 03:04:55 2012
New Revision: 1376354
URL: http://svn.apache.org/viewvc?rev=1376354&view=rev
Log:
[FUNCTOR-14] Adding new classes and simplifying the Generator interface
Added:
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java (with props)
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/package-info.java (with props)
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/IntegerRange.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/LongRange.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/Ranges.java (with props)
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/package-info.java (with props)
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java (with props)
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/TestIntegerRange.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/TestLongRange.java
- copied, changed from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java
Removed:
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java
Modified:
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/EachElement.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/TestAlgorithms.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/Lines.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java
commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java Thu Aug 23 03:04:55 2012
@@ -21,20 +21,21 @@ import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.generator.Generator;
+import org.apache.commons.functor.generator.loop.LoopGenerator;
/**
- * Return the index of the first Object in a {@link Generator} matching a {@link UnaryPredicate}, or -1 if not found.
+ * Return the index of the first Object in a {@link LoopGenerator} matching a
+ * {@link UnaryPredicate}, or -1 if not found.
*
* @param <T> the procedure argument types
* @version $Revision$ $Date$
*/
public final class IndexOfInGenerator<T>
- implements BinaryFunction<Generator<? extends T>, UnaryPredicate<? super T>, Number>, Serializable {
+ implements BinaryFunction<LoopGenerator<? extends T>, UnaryPredicate<? super T>, Number>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -11365986575536471L;
+ private static final long serialVersionUID = -2672603607256310480L;
/**
* A static {@code IndexOfInGenerator} instance reference.
*/
@@ -49,7 +50,7 @@ public final class IndexOfInGenerator<T>
/**
* The wrapped generator.
*/
- private final Generator<? extends T> generator;
+ private final LoopGenerator<? extends T> generator;
/**
* The wrapped predicate.
*/
@@ -70,7 +71,7 @@ public final class IndexOfInGenerator<T>
* @param generator The wrapped generator
* @param pred The wrapped predicate
*/
- IndexProcedure(Generator<? extends T> generator, UnaryPredicate<? super T> pred) {
+ IndexProcedure(LoopGenerator<? extends T> generator, UnaryPredicate<? super T> pred) {
this.generator = generator;
this.pred = pred;
}
@@ -92,7 +93,7 @@ public final class IndexOfInGenerator<T>
* @param left Generator
* @param right UnaryPredicate
*/
- public Number evaluate(Generator<? extends T> left, UnaryPredicate<? super T> right) {
+ public Number evaluate(LoopGenerator<? extends T> left, UnaryPredicate<? super T> right) {
IndexProcedure<T> findProcedure = new IndexProcedure<T>(left, right);
left.run(findProcedure);
return Long.valueOf(findProcedure.index);
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java Thu Aug 23 03:04:55 2012
@@ -29,52 +29,9 @@ import org.apache.commons.functor.genera
*/
public abstract class BaseGenerator<E> implements Generator<E> {
- /** A generator can wrap another generator. */
- private final Generator<?> wrappedGenerator;
-
- /** Set to true when the generator is {@link #stop stopped}. */
- private boolean stopped = false;
-
/** Create a new generator. */
public BaseGenerator() {
- this(null);
- }
-
- /**
- * A generator can wrap another generator. When wrapping generators you
- * should use probably this constructor since doing so will cause the
- * {@link #stop} method to stop the wrapped generator as well.
- * @param generator Generator to wrap
- */
- public BaseGenerator(Generator<?> generator) {
- this.wrappedGenerator = generator;
- }
-
- /**
- * Get the generator that is being wrapped.
- * @return Generator
- */
- protected Generator<?> getWrappedGenerator() {
- return wrappedGenerator;
- }
-
- /**
- * {@inheritDoc}
- * Stop the generator. Will stop the wrapped generator if one was set.
- */
- public void stop() {
- if (wrappedGenerator != null) {
- wrappedGenerator.stop();
- }
- stopped = true;
- }
-
- /**
- * {@inheritDoc}
- * Check if the generator is stopped.
- */
- public boolean isStopped() {
- return stopped;
+ super();
}
/**
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java Thu Aug 23 03:04:55 2012
@@ -31,7 +31,12 @@ import org.apache.commons.lang3.Validate
public class FilteredGenerator<E> extends BaseGenerator<E> {
/**
- * The wrapped generator.
+ * A generator can wrap another generator.
+ * */
+ private Generator<? extends E> wrappedGenerator;
+
+ /**
+ * The predicate used to filter.
*/
private final UnaryPredicate<? super E> pred;
@@ -41,7 +46,7 @@ public class FilteredGenerator<E> extend
* @param pred filtering UnaryPredicate
*/
public FilteredGenerator(Generator<? extends E> wrapped, UnaryPredicate<? super E> pred) {
- super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.wrappedGenerator = Validate.notNull(wrapped, "Generator argument was null");
this.pred = Validate.notNull(pred, "UnaryPredicate argument was null");
}
@@ -53,12 +58,11 @@ public class FilteredGenerator<E> extend
}
/**
- * {@inheritDoc}
+ * Gets the wrapped generator.
+ * @return the wrapped Generator.
*/
- @SuppressWarnings("unchecked")
- @Override
protected Generator<? extends E> getWrappedGenerator() {
- return (Generator<? extends E>) super.getWrappedGenerator();
+ return this.wrappedGenerator;
}
/**
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/Generator.java Thu Aug 23 03:04:55 2012
@@ -33,17 +33,6 @@ public interface Generator<E> {
void run(UnaryProcedure<? super E> proc);
/**
- * Stop the generator. Will stop the wrapped generator if one was set.
- */
- void stop();
-
- /**
- * Check if the generator is stopped.
- * @return true if stopped
- */
- boolean isStopped();
-
- /**
* Transforms this generator using the passed in
* transformer. An example transformer might turn the contents of the
* generator into a {@link Collection} of elements.
@@ -55,6 +44,7 @@ public interface Generator<E> {
/**
* Same as to(new CollectionTransformer(collection)).
+ * @param <C> the returned collection type.
* @param collection Collection to which my elements should be added
* @return <code>collection</code>
*/
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java Thu Aug 23 03:04:55 2012
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.generator.Generator;
import org.apache.commons.lang3.Validate;
/**
@@ -27,7 +28,7 @@ import org.apache.commons.lang3.Validate
* @param <E> the type of elements held in this generator.
* @version $Revision$ $Date$
*/
-public class GenerateUntil<E> extends BaseGenerator<E> {
+public class GenerateUntil<E> extends LoopGenerator<E> {
/**
* The condition has to verified in order to execute the generation.
@@ -52,7 +53,7 @@ public class GenerateUntil<E> extends Ba
public void run(E obj) {
proc.run(obj);
if (test.test(obj)) {
- getWrappedGenerator().stop();
+ GenerateUntil.this.stop();
}
}
});
@@ -61,15 +62,6 @@ public class GenerateUntil<E> extends Ba
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
- @Override
- protected Generator<? extends E> getWrappedGenerator() {
- return (Generator<? extends E>) super.getWrappedGenerator();
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object obj) {
if (obj == this) {
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java Thu Aug 23 03:04:55 2012
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.generator.Generator;
import org.apache.commons.lang3.Validate;
/**
@@ -27,7 +28,7 @@ import org.apache.commons.lang3.Validate
* @param <E> the type of elements held in this generator.
* @version $Revision$ $Date$
*/
-public class GenerateWhile<E> extends BaseGenerator<E> {
+public class GenerateWhile<E> extends LoopGenerator<E> {
/**
* The condition has to verified in order to execute the generation.
@@ -52,7 +53,7 @@ public class GenerateWhile<E> extends Ba
public void run(E obj) {
proc.run(obj);
if (!test.test(obj)) {
- getWrappedGenerator().stop();
+ GenerateWhile.this.stop();
}
}
});
@@ -61,15 +62,6 @@ public class GenerateWhile<E> extends Ba
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
- @Override
- protected Generator<? extends E> getWrappedGenerator() {
- return (Generator<? extends E>) super.getWrappedGenerator();
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object obj) {
if (obj == this) {
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java Thu Aug 23 03:04:55 2012
@@ -12,21 +12,21 @@
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
+
+import java.util.Iterator;
import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.lang3.Validate;
-import java.util.Iterator;
-
/**
- * Adapts an {@link Iterator} to the {@link Generator} interface.
+ * Adapts an {@link Iterator} to the {@link LoopGenerator} interface.
*
* @param <E> the type of elements held in this generator.
* @since 1.0
* @version $Revision$ $Date$
*/
-public final class IteratorToGeneratorAdapter<E> extends BaseGenerator<E> {
+public final class IteratorToGeneratorAdapter<E> extends LoopGenerator<E> {
// instance variables
//-----------------------------------------------------
Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java?rev=1376354&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java Thu Aug 23 03:04:55 2012
@@ -0,0 +1,78 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.functor.generator.loop;
+
+import org.apache.commons.functor.generator.BaseGenerator;
+import org.apache.commons.functor.generator.Generator;
+
+/**
+ * Base class for generators that control execution flow, and may need to
+ * stop the generation.
+ *
+ * @param <E> the type of elements held in this generator.
+ * @since 1.0
+ * @version $Revision:$ $Date:$
+ */
+public abstract class LoopGenerator<E> extends BaseGenerator<E> {
+
+ /** A generator can wrap another generator. */
+ private final Generator<? extends E> wrappedGenerator;
+
+ /** Set to true when the generator is {@link #stop stopped}. */
+ private boolean stopped = false;
+
+ /** Create a new generator. */
+ public LoopGenerator() {
+ this(null);
+ }
+
+ /**
+ * A generator can wrap another generator. When wrapping generators you
+ * should use probably this constructor since doing so will cause the
+ * {@link #stop} method to stop the wrapped generator as well.
+ * @param generator Generator to wrap
+ */
+ public LoopGenerator(Generator<? extends E> generator) {
+ this.wrappedGenerator = generator;
+ }
+
+ /**
+ * Get the generator that is being wrapped.
+ * @return Generator
+ */
+ protected Generator<? extends E> getWrappedGenerator() {
+ return wrappedGenerator;
+ }
+
+ /**
+ * {@inheritDoc}
+ * Stop the generator. Will stop the wrapped generator if one was set.
+ */
+ public void stop() {
+ if (wrappedGenerator != null && wrappedGenerator instanceof LoopGenerator<?>) {
+ ((LoopGenerator<?>) wrappedGenerator).stop();
+ }
+ stopped = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ * Check if the generator is stopped.
+ */
+ public boolean isStopped() {
+ return stopped;
+ }
+
+}
Propchange: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java Thu Aug 23 03:04:55 2012
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.generator.Generator;
import org.apache.commons.lang3.Validate;
/**
@@ -27,28 +28,34 @@ import org.apache.commons.lang3.Validate
* @param <E> the type of elements held in this generator.
* @version $Revision$ $Date$
*/
-public class TransformedGenerator<I, E> extends BaseGenerator<E> {
+public class TransformedGenerator<I, E> extends LoopGenerator<E> {
/**
* The UnaryFunction to apply to each element.
*/
private final UnaryFunction<? super I, ? extends E> func;
+ // This is a special generator, that wraps a generator, but returns another one.
+ // So it breaks the interface contract, and we suppress the warnings when we cast
+ // the wrapped generator. This class has been marked as final, to avoid bogus
+ // specializations.
/**
* Create a new TransformedGenerator.
* @param wrapped Generator to transform
* @param func UnaryFunction to apply to each element
*/
+ @SuppressWarnings("unchecked")
public TransformedGenerator(Generator<? extends I> wrapped, UnaryFunction<? super I, ? extends E> func) {
- super(Validate.notNull(wrapped, "Generator argument was null"));
+ super((Generator<? extends E>) Validate.notNull(wrapped, "Generator argument was null"));
this.func = Validate.notNull(func, "UnaryFunction argument was null");
}
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
public void run(final UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new UnaryProcedure<I>() {
+ ((Generator<? extends I>) getWrappedGenerator()).run(new UnaryProcedure<I>() {
public void run(I obj) {
proc.run(func.evaluate(obj));
}
@@ -58,15 +65,6 @@ public class TransformedGenerator<I, E>
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
- @Override
- protected Generator<? extends I> getWrappedGenerator() {
- return (Generator<? extends I>) super.getWrappedGenerator();
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object obj) {
if (obj == this) {
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java Thu Aug 23 03:04:55 2012
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.generator.Generator;
import org.apache.commons.lang3.Validate;
/**
@@ -27,7 +28,7 @@ import org.apache.commons.lang3.Validate
* @param <E> the type of elements held in this generator.
* @version $Revision$ $Date$
*/
-public class UntilGenerate<E> extends BaseGenerator<E> {
+public class UntilGenerate<E> extends LoopGenerator<E> {
/**
* The condition has to verified in order to execute the generation.
@@ -51,7 +52,7 @@ public class UntilGenerate<E> extends Ba
getWrappedGenerator().run(new UnaryProcedure<E>() {
public void run(E obj) {
if (test.test(obj)) {
- getWrappedGenerator().stop();
+ UntilGenerate.this.stop();
} else {
proc.run(obj);
}
@@ -62,15 +63,6 @@ public class UntilGenerate<E> extends Ba
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
- @Override
- protected Generator<? extends E> getWrappedGenerator() {
- return (Generator<? extends E>) super.getWrappedGenerator();
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object obj) {
if (obj == this) {
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java Thu Aug 23 03:04:55 2012
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.generator.Generator;
import org.apache.commons.lang3.Validate;
/**
@@ -27,7 +28,7 @@ import org.apache.commons.lang3.Validate
* @param <E> the type of elements held in this generator.
* @version $Revision$ $Date$
*/
-public class WhileGenerate<E> extends BaseGenerator<E> {
+public class WhileGenerate<E> extends LoopGenerator<E> {
/**
* The condition has to verified in order to execute the generation.
@@ -51,7 +52,7 @@ public class WhileGenerate<E> extends Ba
getWrappedGenerator().run(new UnaryProcedure<E>() {
public void run(E obj) {
if (!test.test(obj)) {
- getWrappedGenerator().stop();
+ WhileGenerate.this.stop();
} else {
proc.run(obj);
}
@@ -62,15 +63,6 @@ public class WhileGenerate<E> extends Ba
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
- @Override
- protected Generator<? extends E> getWrappedGenerator() {
- return (Generator<? extends E>) super.getWrappedGenerator();
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object obj) {
if (obj == this) {
Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/package-info.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/package-info.java?rev=1376354&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/package-info.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/package-info.java Thu Aug 23 03:04:55 2012
@@ -0,0 +1,19 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * <p>
+ * Contains code related to Generators that control execution flow.
+ * </p>
+ */
+package org.apache.commons.functor.generator.loop;
Propchange: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/loop/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/IntegerRange.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/IntegerRange.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/IntegerRange.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/IntegerRange.java Thu Aug 23 03:04:55 2012
@@ -12,10 +12,10 @@
* limitations under the License.
*/
-package org.apache.commons.functor.generator.util;
+package org.apache.commons.functor.generator.range;
import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.generator.BaseGenerator;
+import org.apache.commons.functor.generator.loop.LoopGenerator;
/**
@@ -24,7 +24,7 @@ import org.apache.commons.functor.genera
* @since 1.0
* @version $Revision$ $Date$
*/
-public final class IntegerGenerator extends BaseGenerator<Integer> {
+public final class IntegerRange extends LoopGenerator<Integer> {
// attributes
//---------------------------------------------------------------
@@ -50,7 +50,7 @@ public final class IntegerGenerator exte
* @param from start
* @param to end
*/
- public IntegerGenerator(Number from, Number to) {
+ public IntegerRange(Number from, Number to) {
this(from.intValue(), to.intValue());
}
@@ -60,7 +60,7 @@ public final class IntegerGenerator exte
* @param to end
* @param step increment
*/
- public IntegerGenerator(Number from, Number to, Number step) {
+ public IntegerRange(Number from, Number to, Number step) {
this(from.intValue(), to.intValue(), step.intValue());
}
@@ -69,7 +69,7 @@ public final class IntegerGenerator exte
* @param from start
* @param to end
*/
- public IntegerGenerator(int from, int to) {
+ public IntegerRange(int from, int to) {
this(from, to, defaultStep(from, to));
}
@@ -79,7 +79,7 @@ public final class IntegerGenerator exte
* @param to end
* @param step increment
*/
- public IntegerGenerator(int from, int to, int step) {
+ public IntegerRange(int from, int to, int step) {
if (from != to && signOf(step) != signOf(to - from)) {
throw new IllegalArgumentException("Will never reach " + to + " from " + from + " using step " + step);
}
@@ -121,10 +121,10 @@ public final class IntegerGenerator exte
if (obj == this) {
return true;
}
- if (!(obj instanceof IntegerGenerator)) {
+ if (!(obj instanceof IntegerRange)) {
return false;
}
- IntegerGenerator that = (IntegerGenerator) obj;
+ IntegerRange that = (IntegerRange) obj;
return this.from == that.from && this.to == that.to && this.step == that.step;
}
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/LongRange.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongGenerator.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/LongRange.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/LongRange.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongGenerator.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/LongRange.java Thu Aug 23 03:04:55 2012
@@ -12,10 +12,10 @@
* limitations under the License.
*/
-package org.apache.commons.functor.generator.util;
+package org.apache.commons.functor.generator.range;
import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.generator.BaseGenerator;
+import org.apache.commons.functor.generator.loop.LoopGenerator;
/**
* A generator for the range <i>from</i> (inclusive) to <i>to</i> (exclusive).
@@ -23,7 +23,7 @@ import org.apache.commons.functor.genera
* @since 1.0
* @version $Revision$ $Date$
*/
-public final class LongGenerator extends BaseGenerator<Long> {
+public final class LongRange extends LoopGenerator<Long> {
// attributes
//---------------------------------------------------------------
@@ -49,7 +49,7 @@ public final class LongGenerator extends
* @param from start
* @param to end
*/
- public LongGenerator(Number from, Number to) {
+ public LongRange(Number from, Number to) {
this(from.longValue(), to.longValue());
}
@@ -59,7 +59,7 @@ public final class LongGenerator extends
* @param to end
* @param step increment
*/
- public LongGenerator(Number from, Number to, Number step) {
+ public LongRange(Number from, Number to, Number step) {
this(from.longValue(), to.longValue(), step.longValue());
}
@@ -68,7 +68,7 @@ public final class LongGenerator extends
* @param from start
* @param to end
*/
- public LongGenerator(long from, long to) {
+ public LongRange(long from, long to) {
this(from, to, defaultStep(from, to));
}
@@ -78,7 +78,7 @@ public final class LongGenerator extends
* @param to end
* @param step increment
*/
- public LongGenerator(long from, long to, long step) {
+ public LongRange(long from, long to, long step) {
if (from != to && signOf(step) != signOf(to - from)) {
throw new IllegalArgumentException("Will never reach " + to + " from " + from + " using step " + step);
}
@@ -120,10 +120,10 @@ public final class LongGenerator extends
if (obj == this) {
return true;
}
- if (!(obj instanceof LongGenerator)) {
+ if (!(obj instanceof LongRange)) {
return false;
}
- LongGenerator that = (LongGenerator) obj;
+ LongRange that = (LongRange) obj;
return this.from == that.from && this.to == that.to && this.step == that.step;
}
Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/Ranges.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/Ranges.java?rev=1376354&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/Ranges.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/Ranges.java Thu Aug 23 03:04:55 2012
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.generator.range;
+
+/**
+ * Range factory.
+ *
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public class Ranges {
+
+}
Propchange: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/Ranges.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/package-info.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/package-info.java?rev=1376354&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/package-info.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/package-info.java Thu Aug 23 03:04:55 2012
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * <p>
+ * Contains code related to Ranges.
+ * </p>
+ */
+package org.apache.commons.functor.generator.range;
Propchange: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java Thu Aug 23 03:04:55 2012
@@ -27,10 +27,12 @@ import org.apache.commons.lang3.Validate
* the constructor an ArrayList will be returned from the transform method.
*
* @param <E> the type of elements held in the adapted collection.
+ * @param <C> the type of collection to be filled.
* @since 1.0
* @version $Revision$ $Date$
*/
-public class CollectionTransformer<E, C extends Collection<? super E>> implements UnaryFunction<Generator<? extends E>, C> {
+public class CollectionTransformer<E, C extends Collection<? super E>>
+ implements UnaryFunction<Generator<? extends E>, C> {
/*
* TODO revisit this class... it could stand a more-descriptive name. Also, it's a little
* hard to say whether, for an instance constructed without a specific target collection,
@@ -72,6 +74,7 @@ public class CollectionTransformer<E, C
/**
* Get a {@link CollectionTransformer} instance that simply returns any {@link Collection}.
+ * @param <E> the returned collection type.
* @return {@link CollectionTransformer}
*/
public static <E> CollectionTransformer<E, Collection<E>> toCollection() {
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/EachElement.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/EachElement.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/EachElement.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/EachElement.java Thu Aug 23 03:04:55 2012
@@ -19,7 +19,7 @@ import java.util.Iterator;
import java.util.Map;
import org.apache.commons.functor.generator.Generator;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
/**
* Generator factory for each element of a "collection".
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/TestAlgorithms.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/TestAlgorithms.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/TestAlgorithms.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/TestAlgorithms.java Thu Aug 23 03:04:55 2012
@@ -31,10 +31,10 @@ import java.util.Set;
import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.composite.UnaryNot;
import org.apache.commons.functor.generator.FilteredGenerator;
-import org.apache.commons.functor.generator.Generator;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
-import org.apache.commons.functor.generator.TransformedGenerator;
-import org.apache.commons.functor.generator.util.IntegerGenerator;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.LoopGenerator;
+import org.apache.commons.functor.generator.loop.TransformedGenerator;
+import org.apache.commons.functor.generator.range.IntegerRange;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -116,7 +116,7 @@ public class TestAlgorithms {
@Test
public void testApplyToGenerator() {
- Generator<Integer> gen = new IntegerGenerator(1,5);
+ LoopGenerator<Integer> gen = new IntegerRange(1,5);
Summer summer = new Summer();
new TransformedGenerator<Integer, Integer>(gen, new Doubler()).run(summer);
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java Thu Aug 23 03:04:55 2012
@@ -28,7 +28,7 @@ import org.apache.commons.functor.BaseFu
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.IsEqual;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.Test;
/**
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java Thu Aug 23 03:04:55 2012
@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.Test;
/**
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java Thu Aug 23 03:04:55 2012
@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.Test;
/**
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java Thu Aug 23 03:04:55 2012
@@ -27,7 +27,7 @@ import org.apache.commons.functor.UnaryP
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.IsEqual;
import org.apache.commons.functor.core.algorithm.GeneratorContains;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.Test;
/**
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java Thu Aug 23 03:04:55 2012
@@ -25,7 +25,7 @@ import org.apache.commons.functor.BaseFu
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.IsEqual;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.Test;
/**
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/QuicksortExample.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/QuicksortExample.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/QuicksortExample.java Thu Aug 23 03:04:55 2012
@@ -33,7 +33,7 @@ import org.apache.commons.functor.core.c
import org.apache.commons.functor.core.comparator.IsLessThan;
import org.apache.commons.functor.core.composite.ConditionalUnaryFunction;
import org.apache.commons.functor.generator.FilteredGenerator;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.Test;
/*
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java Thu Aug 23 03:04:55 2012
@@ -26,7 +26,7 @@ import org.apache.commons.functor.Predic
import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.algorithm.RecursiveEvaluation;
import org.apache.commons.functor.core.algorithm.UntilDo;
-import org.apache.commons.functor.generator.util.IntegerGenerator;
+import org.apache.commons.functor.generator.range.IntegerRange;
import org.junit.Test;
/**
@@ -102,7 +102,7 @@ public class TestBinaryChop {
assertEquals(-1, chopper.find(6, new int[] { 1, 3, 5, 7 }));
assertEquals(-1, chopper.find(8, new int[] { 1, 3, 5, 7 }));
- List<Integer> largeList = (List<Integer>) (new IntegerGenerator(0, 100001).toCollection());
+ List<Integer> largeList = (List<Integer>) (new IntegerRange(0, 100001).toCollection());
assertEquals(-1, chopper.find(new Integer(-5), largeList));
assertEquals(100000, chopper.find(new Integer(100000), largeList));
assertEquals(0, chopper.find(new Integer(0), largeList));
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/Lines.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/Lines.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/Lines.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/Lines.java Thu Aug 23 03:04:55 2012
@@ -23,12 +23,12 @@ import java.io.FileReader;
import java.io.Reader;
import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.generator.BaseGenerator;
+import org.apache.commons.functor.generator.loop.LoopGenerator;
/**
* @version $Revision$ $Date$
*/
-public class Lines extends BaseGenerator<String> {
+public class Lines extends LoopGenerator<String> {
public static Lines from(Reader reader) {
return new Lines(reader);
}
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/TestLines.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/TestLines.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/lines/TestLines.java Thu Aug 23 03:04:55 2012
@@ -31,7 +31,7 @@ import org.apache.commons.functor.core.c
import org.apache.commons.functor.core.composite.UnaryAnd;
import org.apache.commons.functor.core.composite.UnaryNot;
import org.apache.commons.functor.generator.FilteredGenerator;
-import org.apache.commons.functor.generator.TransformedGenerator;
+import org.apache.commons.functor.generator.loop.TransformedGenerator;
/**
* @version $Revision$ $Date$
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java Thu Aug 23 03:04:55 2012
@@ -24,7 +24,7 @@ import org.apache.commons.functor.Binary
import org.apache.commons.functor.adapter.BinaryProcedureBinaryFunction;
import org.apache.commons.functor.core.algorithm.GeneratorContains;
import org.apache.commons.functor.core.composite.UnaryNot;
-import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
/**
* @version $Revision$ $Date$
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java Thu Aug 23 03:04:55 2012
@@ -47,9 +47,6 @@ public class TestBaseGenerator {
public void run(UnaryProcedure<? super Integer> proc) {
for (int i=0;i<5;i++) {
proc.run(new Integer(i));
- if (isStopped()) {
- break;
- }
}
}
};
@@ -95,60 +92,6 @@ public class TestBaseGenerator {
assertEquals("01234", result.toString());
}
- @Test
- public void testStop() {
- final StringBuffer result = new StringBuffer();
- simpleGenerator.run(new UnaryProcedure<Integer>() {
- int i=0;
- public void run(Integer obj) {
- result.append(obj);
- if (i++ > 1) {
- simpleGenerator.stop();
- }
- }
- });
-
- assertEquals("012", result.toString());
- }
-
- @Test
- public void testWrappingGenerator() {
- final StringBuffer result = new StringBuffer();
- final Generator<Integer> gen = new BaseGenerator<Integer>(simpleGenerator) {
- public void run(final UnaryProcedure<? super Integer> proc) {
- Generator<Integer> wrapped = (Generator<Integer>)getWrappedGenerator();
- assertSame(simpleGenerator, wrapped);
- wrapped.run(new UnaryProcedure<Integer>() {
- public void run(Integer obj) {
- proc.run(new Integer(obj.intValue() + 1));
- }
- });
- }
- };
-
- gen.run(new UnaryProcedure<Integer>() {
- public void run(Integer obj) {
- result.append(obj);
- }
- });
-
- assertEquals("12345", result.toString());
-
- // try to stop the wrapped generator
- final StringBuffer result2 = new StringBuffer();
- gen.run(new UnaryProcedure<Integer>() {
- int i=0;
- public void run(Integer obj) {
- result2.append(obj);
- if (i++ > 1) {
- gen.stop();
- }
- }
- });
-
- assertEquals("123", result2.toString());
- }
-
// Tests
// ------------------------------------------------------------------------
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java?rev=1376354&r1=1376353&r2=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java Thu Aug 23 03:04:55 2012
@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.generator.util.IntegerGenerator;
+import org.apache.commons.functor.generator.range.IntegerRange;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -39,7 +39,7 @@ public class TestFilteredGenerator
@Before
public void setUp() throws Exception {
- wrappedGenerator = new IntegerGenerator(1, 10);
+ wrappedGenerator = new IntegerRange(1, 10);
filteredGenerator = new FilteredGenerator<Integer>(wrappedGenerator, isEven);
}
@@ -70,13 +70,13 @@ public class TestFilteredGenerator
@Test
public void testEquals() {
- Generator<Integer> anotherGenerate = new FilteredGenerator<Integer>(new IntegerGenerator(1, 10), isEven);
+ Generator<Integer> anotherGenerate = new FilteredGenerator<Integer>(new IntegerRange(1, 10), isEven);
assertEquals(filteredGenerator, filteredGenerator);
assertEquals(filteredGenerator, anotherGenerate);
assertTrue(!filteredGenerator.equals((FilteredGenerator<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new FilteredGenerator<Integer>(
- new IntegerGenerator(1, 10), new UnaryPredicate<Integer>() {
+ new IntegerRange(1, 10), new UnaryPredicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 == 0;
}
@@ -84,7 +84,7 @@ public class TestFilteredGenerator
assertTrue(!filteredGenerator.equals(aGenerateWithADifferentPredicate));
- Generator<Integer> aGenerateWithADifferentWrapped = new FilteredGenerator<Integer>(new IntegerGenerator(1,11), isEven);
+ Generator<Integer> aGenerateWithADifferentWrapped = new FilteredGenerator<Integer>(new IntegerRange(1,11), isEven);
assertTrue(!filteredGenerator.equals(aGenerateWithADifferentWrapped));
}
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java Thu Aug 23 03:04:55 2012
@@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.generator.util.IntegerGenerator;
+import org.apache.commons.functor.generator.Generator;
+import org.apache.commons.functor.generator.range.IntegerRange;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -34,7 +35,7 @@ public class TestGenerateUntil
@Before
public void setUp() throws Exception {
- wrappedGenerator = new IntegerGenerator(1, 10);
+ wrappedGenerator = new IntegerRange(1, 10);
generateUntil = new GenerateUntil<Integer>(wrappedGenerator, isMoreThanFive);
}
@@ -65,13 +66,13 @@ public class TestGenerateUntil
@Test
public void testEquals() {
- Generator<Integer> anotherGenerate = new GenerateUntil<Integer>(new IntegerGenerator(1, 10), isMoreThanFive);
+ Generator<Integer> anotherGenerate = new GenerateUntil<Integer>(new IntegerRange(1, 10), isMoreThanFive);
assertEquals(generateUntil, generateUntil);
assertEquals(generateUntil, anotherGenerate);
assertTrue(!generateUntil.equals((GenerateUntil<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new GenerateUntil<Integer>(
- new IntegerGenerator(1, 10),
+ new IntegerRange(1, 10),
new UnaryPredicate<Integer>() {
public boolean test(Integer obj) {
return obj > FIVE;
@@ -79,7 +80,7 @@ public class TestGenerateUntil
});
assertTrue(!generateUntil.equals(aGenerateWithADifferentPredicate));
- Generator<Integer> aGenerateWithADifferentWrapped = new GenerateUntil<Integer>(new IntegerGenerator(1,2), isMoreThanFive);
+ Generator<Integer> aGenerateWithADifferentWrapped = new GenerateUntil<Integer>(new IntegerRange(1,2), isMoreThanFive);
assertTrue(!generateUntil.equals(aGenerateWithADifferentWrapped));
}
@@ -93,11 +94,11 @@ public class TestGenerateUntil
// ------------------------------------------------------------------------
private static final Integer FIVE = new Integer(5);
- private Generator<Integer> wrappedGenerator = null;
+ private LoopGenerator<Integer> wrappedGenerator = null;
private UnaryPredicate<Integer> isMoreThanFive = new UnaryPredicate<Integer>() {
public boolean test( Integer obj ) {
return obj > FIVE;
}
};
- private Generator<Integer> generateUntil = null;
+ private LoopGenerator<Integer> generateUntil = null;
}
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java Thu Aug 23 03:04:55 2012
@@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.generator.util.IntegerGenerator;
+import org.apache.commons.functor.generator.Generator;
+import org.apache.commons.functor.generator.range.IntegerRange;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -34,7 +35,7 @@ public class TestGenerateWhile
@Before
public void setUp() throws Exception {
- wrappedGenerator = new IntegerGenerator(1, 10);
+ wrappedGenerator = new IntegerRange(1, 10);
generateWhile = new GenerateWhile<Integer>(wrappedGenerator, isLessThanFive);
}
@@ -65,13 +66,13 @@ public class TestGenerateWhile
@Test
public void testEquals() {
- Generator<Integer> anotherGenerate = new GenerateWhile<Integer>(new IntegerGenerator(1, 10), isLessThanFive);
+ Generator<Integer> anotherGenerate = new GenerateWhile<Integer>(new IntegerRange(1, 10), isLessThanFive);
assertEquals(generateWhile, generateWhile);
assertEquals(generateWhile, anotherGenerate);
assertTrue(!generateWhile.equals((GenerateWhile<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new GenerateWhile<Integer>(
- new IntegerGenerator(1, 10), new UnaryPredicate<Integer>() {
+ new IntegerRange(1, 10), new UnaryPredicate<Integer>() {
public boolean test(Integer obj) {
return obj < FIVE;
}
@@ -79,7 +80,7 @@ public class TestGenerateWhile
assertTrue(!generateWhile.equals(aGenerateWithADifferentPredicate));
- Generator<Integer> aGenerateWithADifferentWrapped = new GenerateWhile<Integer>(new IntegerGenerator(1,11), isLessThanFive);
+ Generator<Integer> aGenerateWithADifferentWrapped = new GenerateWhile<Integer>(new IntegerRange(1,11), isLessThanFive);
assertTrue(!generateWhile.equals(aGenerateWithADifferentWrapped));
}
@@ -93,13 +94,13 @@ public class TestGenerateWhile
// ------------------------------------------------------------------------
private static final Integer FIVE = new Integer(5);
- private Generator<Integer> wrappedGenerator = null;
+ private LoopGenerator<Integer> wrappedGenerator = null;
private UnaryPredicate<Integer> isLessThanFive = new UnaryPredicate<Integer>()
{
public boolean test( Integer obj ) {
return obj < FIVE;
}
};
- private Generator<Integer> generateWhile = null;
+ private LoopGenerator<Integer> generateWhile = null;
}
Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java (from r1375524, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java)
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java&p1=commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java&r1=1375524&r2=1376354&rev=1376354&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java Thu Aug 23 03:04:55 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.functor.generator;
+package org.apache.commons.functor.generator.loop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -26,6 +26,8 @@ import java.util.Iterator;
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.generator.Generator;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;