commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ki...@apache.org
Subject svn commit: r1515264 [1/2] - in /commons/proper/functor/branches/generators-FUNCTOR-14/src: main/java/org/apache/commons/functor/generator/range/ main/java/org/apache/commons/functor/range/ test/java/org/apache/commons/functor/ test/java/org/apache/com...
Date Mon, 19 Aug 2013 02:51:42 GMT
Author: kinow
Date: Mon Aug 19 02:51:41 2013
New Revision: 1515264

URL: http://svn.apache.org/r1515264
Log:
Create ranges package and make it iterable and iterator, rather than a generator

Added:
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/BoundType.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Endpoint.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/LongRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/NumericRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Range.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Ranges.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/package-info.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/
      - copied from r1515159, commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/
Removed:
    commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/range/
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/
Modified:
    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/example/kata/two/TestBinaryChop.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/loop/TestGenerateUntil.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/TestEndpoint.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/TestFloatRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java
    commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/range/TestLongRange.java

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/BoundType.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/BoundType.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/BoundType.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/BoundType.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.range;
+
+/**
+ * Determine the bound type of a range.
+ *
+ * @see org.apache.commons.functor.generator.range.Range
+ * @see org.apache.commons.functor.generator.range.Endpoint
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public enum BoundType {
+    // values
+    // ---------------------------------------------------------------
+    /**
+     * Represents an <b>open</b> bound, which value <b>is not</b> included in
+     * the range.
+     */
+    OPEN,
+    /**
+     * Represents a <b>closed</b> bound, which value <b>is included</b> in the
+     * range.
+     */
+    CLOSED;
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,351 @@
+/*
+ * 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.range;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * A generator for a range of characters.
+ *
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public final class CharacterRange implements Range<Character, Integer>, Iterable<Character>, Iterator<Character> {
+
+    // attributes
+    // ---------------------------------------------------------------
+    /**
+     * Default left bound type.
+     */
+    public static final BoundType DEFAULT_LEFT_BOUND_TYPE = BoundType.CLOSED;
+
+    /**
+     * Default right bound type.
+     */
+    public static final BoundType DEFAULT_RIGHT_BOUND_TYPE = BoundType.CLOSED;
+
+    /**
+     * Left limit.
+     */
+    private final Endpoint<Character> leftEndpoint;
+
+    /**
+     * Right limit.
+     */
+    private final Endpoint<Character> rightEndpoint;
+
+    /**
+     * Increment step.
+     */
+    private final int step;
+
+    /**
+     * Current value.
+     */
+    private char currentValue;
+
+    /**
+     * Calculate default step.
+     */
+    public static final BinaryFunction<Character, Character, Integer> DEFAULT_STEP
+        = new BinaryFunction<Character, Character, Integer>() {
+
+        public Integer evaluate(Character left, Character right) {
+            return left > right ? -1 : 1;
+        }
+    };
+
+    // constructors
+    // ---------------------------------------------------------------
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public CharacterRange(char from, char to) {
+        this(from, to, DEFAULT_STEP.evaluate(from, to).intValue());
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public CharacterRange(char from, char to, int step) {
+        this(from, BoundType.CLOSED, to, BoundType.CLOSED, step);
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public CharacterRange(Endpoint<Character> from, Endpoint<Character> to) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(),
+                DEFAULT_STEP.evaluate(from.getValue(), to.getValue()));
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public CharacterRange(Endpoint<Character> from, Endpoint<Character> to, int step) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(), step);
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     */
+    public CharacterRange(char from, BoundType leftBoundType, char to,
+                        BoundType rightBoundType) {
+        this(from, leftBoundType, to, rightBoundType, DEFAULT_STEP.evaluate(from, to));
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     */
+    public CharacterRange(char from, BoundType leftBoundType, char to,
+                          BoundType rightBoundType, int step) {
+        this.leftEndpoint = Validate
+            .notNull(new Endpoint<Character>(from, leftBoundType),
+                     "Left Endpoint argument must not be null");
+        this.rightEndpoint = Validate
+            .notNull(new Endpoint<Character>(to, rightBoundType),
+                     "Right Endpoint argument must not be null");
+        this.step = step;
+        if (from != to && Integer.signum(step) != Integer.signum(to - from)) {
+            throw new IllegalArgumentException("Will never reach " + to
+                                               + " from " + from
+                                               + " using step " + step);
+        }
+        if (this.leftEndpoint.getBoundType() == BoundType.CLOSED) {
+            this.currentValue = this.leftEndpoint.getValue();
+        } else {
+            this.currentValue = (char) (this.leftEndpoint.getValue() + this.step);
+        }
+    }
+
+    // range methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Character> getLeftEndpoint() {
+        return this.leftEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Character> getRightEndpoint() {
+        return this.rightEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Integer getStep() {
+        return this.step;
+    }
+
+    // iterable, iterator methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasNext() {
+        final int to = this.rightEndpoint.getValue();
+        if (step < 0) {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue >= to;
+            } else {
+                return this.currentValue > to;
+            }
+        } else {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue <= to;
+            } else {
+                return this.currentValue < to;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Character next() {
+        final int step = this.getStep();
+        final char r = this.currentValue;
+        this.currentValue += step;
+        return r;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Character> iterator() {
+        return this;
+    }
+
+    // object methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "CharacterRange<" + this.leftEndpoint.toLeftString() + ", "
+                + this.rightEndpoint.toRightString() + ", " + step + ">";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof CharacterRange)) {
+            return false;
+        }
+        CharacterRange that = (CharacterRange) obj;
+        return this.leftEndpoint.equals(that.leftEndpoint)
+                && this.rightEndpoint.equals(that.rightEndpoint)
+                && this.step == that.step;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int hash = "CharacterRange".hashCode();
+        hash <<= 2;
+        hash ^= this.leftEndpoint.getValue();
+        hash <<= 2;
+        hash ^= this.rightEndpoint.getValue();
+        hash <<= 2;
+        hash ^= this.step;
+        return hash;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        double leftValue = this.getLeftEndpoint().getValue().charValue();
+        double rightValue = this.getRightEndpoint().getValue().charValue();
+        boolean closedLeft = this.getLeftEndpoint().getBoundType() == BoundType.CLOSED;
+        boolean closedRight = this.getRightEndpoint().getBoundType() == BoundType.CLOSED;
+        if (!closedLeft && !closedRight
+                && this.getLeftEndpoint().equals(this.getRightEndpoint())) {
+            return Boolean.TRUE;
+        }
+        double step = this.getStep().intValue();
+        if (step > 0.0) {
+            double firstValue = closedLeft ? leftValue : leftValue + step;
+            return closedRight ? firstValue > rightValue
+                              : firstValue >= rightValue;
+        } else {
+            double firstValue = closedLeft ? leftValue : leftValue + step;
+            return closedRight ? firstValue < rightValue
+                              : firstValue <= rightValue;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean contains(Character obj) {
+        if (obj == null) {
+            return Boolean.FALSE;
+        }
+        char leftValue = this.getLeftEndpoint().getValue().charValue();
+        char rightValue = this.getRightEndpoint().getValue().charValue();
+        boolean includeLeft = this.getLeftEndpoint().getBoundType() == BoundType.CLOSED;
+        boolean includeRight = this.getRightEndpoint().getBoundType() == BoundType.CLOSED;
+        int step = this.getStep().intValue();
+        int value = (int) obj.charValue();
+
+        int firstValue = 0;
+        int lastValue = 0;
+
+        if (step < 0.0) {
+            firstValue = includeLeft ? leftValue : leftValue + step;
+            lastValue = includeRight ? rightValue : rightValue + 1;
+            if (value > firstValue || value < lastValue) {
+                return Boolean.FALSE;
+            }
+        } else {
+            firstValue = includeLeft ? leftValue : leftValue + step;
+            lastValue = includeRight ? rightValue : rightValue - 1;
+            if (value < firstValue || value > lastValue) {
+                return Boolean.FALSE;
+            }
+        }
+        return ((double) (value - firstValue) / step + 1) % 1.0 == 0.0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean containsAll(Collection<Character> col) {
+        if (col == null || col.size() == 0) {
+            return Boolean.FALSE;
+        }
+        boolean r = Boolean.TRUE;
+        for (Character t : col) {
+            if (!this.contains(t)) {
+                r = Boolean.FALSE;
+                break;
+            }
+        }
+        return r;
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,286 @@
+/*
+ * 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.range;
+
+import java.util.Iterator;
+
+import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * A generator for a range of doubles.
+ *
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public class DoubleRange extends NumericRange<Double> implements Iterable<Double>, Iterator<Double> {
+
+    // attributes
+    // ---------------------------------------------------------------
+    /**
+     * Left limit.
+     */
+    private final Endpoint<Double> leftEndpoint;
+
+    /**
+     * Right limit.
+     */
+    private final Endpoint<Double> rightEndpoint;
+
+    /**
+     * Increment step.
+     */
+    private final double step;
+
+    /**
+     * Current value.
+     */
+    private double currentValue;
+
+    /**
+     * Calculate default step.
+     */
+    public static final BinaryFunction<Double, Double, Double> DEFAULT_STEP =
+            new BinaryFunction<Double, Double, Double>() {
+
+        public Double evaluate(Double left, Double right) {
+            return left > right ? -1.0d : 1.0d;
+        }
+    };
+
+    // constructors
+    // ---------------------------------------------------------------
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public DoubleRange(Number from, Number to) {
+        this(from.doubleValue(), to.doubleValue());
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public DoubleRange(Number from, Number to, Number step) {
+        this(from.doubleValue(), to.doubleValue(), step.doubleValue());
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public DoubleRange(double from, double to) {
+        this(from, to, DEFAULT_STEP.evaluate(from, to).intValue());
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public DoubleRange(double from, double to, double step) {
+        this(from, DEFAULT_LEFT_BOUND_TYPE, to, DEFAULT_RIGHT_BOUND_TYPE, step);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public DoubleRange(Endpoint<Double> from, Endpoint<Double> to) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(),
+                DEFAULT_STEP.evaluate(from.getValue(), to.getValue()));
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     */
+    public DoubleRange(double from, BoundType leftBoundType, double to,
+                        BoundType rightBoundType) {
+        this(from, leftBoundType, to, rightBoundType, DEFAULT_STEP.evaluate(from, to));
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public DoubleRange(Endpoint<Double> from, Endpoint<Double> to, double step) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(), step);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     */
+    public DoubleRange(double from, BoundType leftBoundType, double to,
+                       BoundType rightBoundType, double step) {
+        this.leftEndpoint = Validate
+            .notNull(new Endpoint<Double>(from, leftBoundType),
+                     "Left Endpoint argument must not be null");
+        this.rightEndpoint = Validate
+            .notNull(new Endpoint<Double>(to, rightBoundType),
+                     "Right Endpoint argument must not be null");
+        this.step = step;
+        if (from != to && Math.signum(step) != Math.signum(to - from)) {
+            throw new IllegalArgumentException("Will never reach " + to
+                                               + " from " + from
+                                               + " using step " + step);
+        }
+        if (this.leftEndpoint.getBoundType() == BoundType.CLOSED) {
+            this.currentValue = this.leftEndpoint.getValue();
+        } else {
+            this.currentValue = this.leftEndpoint.getValue() + this.step;
+        }
+    }
+
+    // range methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Double> getLeftEndpoint() {
+        return this.leftEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Double> getRightEndpoint() {
+        return this.rightEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double getStep() {
+        return this.step;
+    }
+ // iterable, iterator methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasNext() {
+        final double to = this.rightEndpoint.getValue();
+        if (step < 0) {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue >= to;
+            } else {
+                return this.currentValue > to;
+            }
+        } else {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue <= to;
+            } else {
+                return this.currentValue < to;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double next() {
+        final double step = this.getStep();
+        final double r = this.currentValue;
+        this.currentValue += step;
+        return r;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Double> iterator() {
+        return this;
+    }
+
+    // object methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "DoubleRange<" + this.leftEndpoint.toLeftString() + ", "
+                + this.rightEndpoint.toRightString() + ", " + this.step + ">";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof DoubleRange)) {
+            return false;
+        }
+        DoubleRange that = (DoubleRange) obj;
+        return this.leftEndpoint.equals(that.leftEndpoint)
+                && this.rightEndpoint.equals(that.rightEndpoint)
+                && this.step == that.step;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int hash = "DoubleRange".hashCode();
+        hash <<= 2;
+        hash ^= this.leftEndpoint.getValue().hashCode();
+        hash <<= 2;
+        hash ^= this.rightEndpoint.getValue().hashCode();
+        hash <<= 2;
+        hash ^= Double.valueOf(this.step).hashCode();
+        return hash;
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Endpoint.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Endpoint.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Endpoint.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Endpoint.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,122 @@
+/*
+ * 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.range;
+
+/**
+ * Represent an endpoint of a range. This can be the left endpoint or the right
+ * endpoint. It is also called left limit or right limit, and can be open
+ * (exclusive, unbounded) or closed (inclusive, bounded).
+ *
+ * @param <T> type of the value held by this endpoint
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public class Endpoint<T extends Comparable<?>> {
+
+    /**
+     * The endpoint value.
+     */
+    private final T value;
+
+    /**
+     * The endpoint bound type.
+     */
+    private final BoundType boundType;
+
+    /**
+     * Create an endpoint.
+     *
+     * @param value value
+     * @param boundType bound type
+     */
+    public Endpoint(T value, BoundType boundType) {
+        this.value = value;
+        this.boundType = boundType;
+    }
+
+    /**
+     * @return Object
+     */
+    public T getValue() {
+        return value;
+    }
+
+    /**
+     * @return BoundType
+     */
+    public BoundType getBoundType() {
+        return boundType;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        String boundType = this.boundType == BoundType.OPEN ? "OPEN" : "CLOSED";
+        return "Endpoint<" + this.value + ", " + boundType + ">";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof Endpoint)) {
+            return false;
+        }
+        Endpoint<?> that = (Endpoint<?>) obj;
+        return this.boundType == that.boundType
+                && this.value.equals(that.value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int hash = "Endpoint".hashCode();
+        hash <<= 2;
+        hash ^= this.value.toString().hashCode();
+        hash <<= 2;
+        hash ^= Boolean.valueOf(this.boundType == BoundType.OPEN).hashCode();
+        return hash;
+    }
+
+    /**
+     * Print the left endpoint and bound type.
+     *
+     * @return String
+     */
+    public String toLeftString() {
+        return (this.boundType == BoundType.OPEN ? "(" : "[") + this.value;
+    }
+
+    /**
+     * Print the right endpoint and bound type.
+     *
+     * @return String
+     */
+    public String toRightString() {
+        return this.value + (this.boundType == BoundType.OPEN ? ")" : "]");
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,286 @@
+/*
+ * 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.range;
+
+import java.util.Iterator;
+
+import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * A generator for a range of float.
+ *
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public class FloatRange extends NumericRange<Float> implements Iterable<Float>, Iterator<Float> {
+
+    // attributes
+    // ---------------------------------------------------------------
+    /**
+     * Left limit.
+     */
+    private final Endpoint<Float> leftEndpoint;
+
+    /**
+     * Right limit.
+     */
+    private final Endpoint<Float> rightEndpoint;
+
+    /**
+     * Increment step.
+     */
+    private final float step;
+
+    /**
+     * Current value.
+     */
+    private float currentValue;
+
+    /**
+     * Calculate default step.
+     */
+    public static final BinaryFunction<Float, Float, Float> DEFAULT_STEP = new BinaryFunction<Float, Float, Float>() {
+
+        public Float evaluate(Float left, Float right) {
+            return left > right ? -1.0f : 1.0f;
+        }
+    };
+
+    // constructors
+    // ---------------------------------------------------------------
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public FloatRange(Number from, Number to) {
+        this(from.floatValue(), to.floatValue());
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public FloatRange(Number from, Number to, Number step) {
+        this(from.floatValue(), to.floatValue(), step.floatValue());
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public FloatRange(float from, float to) {
+        this(from, to, DEFAULT_STEP.evaluate(from, to).floatValue());
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public FloatRange(float from, float to, float step) {
+        this(from, DEFAULT_LEFT_BOUND_TYPE, to, DEFAULT_RIGHT_BOUND_TYPE, step);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public FloatRange(Endpoint<Float> from, Endpoint<Float> to) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(),
+                DEFAULT_STEP.evaluate(from.getValue(), to.getValue()));
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public FloatRange(Endpoint<Float> from, Endpoint<Float> to, float step) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(), step);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     */
+    public FloatRange(float from, BoundType leftBoundType, float to,
+                        BoundType rightBoundType) {
+        this(from, leftBoundType, to, rightBoundType, DEFAULT_STEP.evaluate(from, to));
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     */
+    public FloatRange(float from, BoundType leftBoundType, float to,
+                      BoundType rightBoundType, float step) {
+        this.leftEndpoint = Validate
+            .notNull(new Endpoint<Float>(from, leftBoundType),
+                     "Left Endpoint argument must not be null");
+        this.rightEndpoint = Validate
+            .notNull(new Endpoint<Float>(to, rightBoundType),
+                     "Right Endpoint argument must not be null");
+        this.step = step;
+        if (from != to && Math.signum(step) != Math.signum(to - from)) {
+            throw new IllegalArgumentException("Will never reach " + to
+                                               + " from " + from
+                                               + " using step " + step);
+        }
+        if (this.leftEndpoint.getBoundType() == BoundType.CLOSED) {
+            this.currentValue = this.leftEndpoint.getValue();
+        } else {
+            this.currentValue = this.leftEndpoint.getValue() + this.step;
+        }
+    }
+
+    // range methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Float> getLeftEndpoint() {
+        return this.leftEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Float> getRightEndpoint() {
+        return this.rightEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Float getStep() {
+        return this.step;
+    }
+
+    // iterable, iterator methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasNext() {
+        final float to = this.rightEndpoint.getValue();
+        if (step < 0) {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue >= to;
+            } else {
+                return this.currentValue > to;
+            }
+        } else {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue <= to;
+            } else {
+                return this.currentValue < to;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Float next() {
+        final float step = this.getStep();
+        final float r = this.currentValue;
+        this.currentValue += step;
+        return r;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Float> iterator() {
+        return this;
+    }
+
+    // object methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "FloatRange<" + this.leftEndpoint.toLeftString() + ", "
+                + this.rightEndpoint.toRightString() + ", " + this.step + ">";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof FloatRange)) {
+            return false;
+        }
+        FloatRange that = (FloatRange) obj;
+        return this.leftEndpoint.equals(that.leftEndpoint)
+                && this.rightEndpoint.equals(that.rightEndpoint)
+                && this.step == that.step;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int hash = "FloatRange".hashCode();
+        hash <<= 2;
+        hash ^= this.leftEndpoint.getValue().hashCode();
+        hash <<= 2;
+        hash ^= this.rightEndpoint.getValue().hashCode();
+        hash <<= 2;
+        hash ^= Float.valueOf(this.step).hashCode();
+        return hash;
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,288 @@
+/*
+ * 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.range;
+
+import java.util.Iterator;
+
+import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * A range of integers.
+ *
+ * @since 1.0
+ * @version $Revision: 1385335 $ $Date: 2012-09-16 15:08:31 -0300 (Sun, 16 Sep 2012) $
+ */
+public class IntegerRange extends NumericRange<Integer> implements Iterable<Integer>, Iterator<Integer> {
+
+    // attributes
+    // ---------------------------------------------------------------
+    /**
+     * Left limit.
+     */
+    private final Endpoint<Integer> leftEndpoint;
+
+    /**
+     * Right limit.
+     */
+    private final Endpoint<Integer> rightEndpoint;
+
+    /**
+     * Increment step.
+     */
+    private final int step;
+
+    /**
+     * Current value.
+     */
+    private int currentValue;
+
+    /**
+     * Calculate default step.
+     */
+    public static final BinaryFunction<Integer, Integer, Integer> DEFAULT_STEP =
+            new BinaryFunction<Integer, Integer, Integer>() {
+
+        public Integer evaluate(Integer left, Integer right) {
+            return left > right ? -1 : 1;
+        }
+    };
+
+    // constructors
+    // ---------------------------------------------------------------
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public IntegerRange(Number from, Number to) {
+        this(from.intValue(), to.intValue());
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public IntegerRange(Number from, Number to, Number step) {
+        this(from.intValue(), to.intValue(), step.intValue());
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public IntegerRange(int from, int to) {
+        this(from, to, DEFAULT_STEP.evaluate(from, to).intValue());
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public IntegerRange(int from, int to, int step) {
+        this(from, DEFAULT_LEFT_BOUND_TYPE, to, DEFAULT_RIGHT_BOUND_TYPE, step);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public IntegerRange(Endpoint<Integer> from, Endpoint<Integer> to) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(),
+                DEFAULT_STEP.evaluate(from.getValue(), to.getValue()));
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public IntegerRange(Endpoint<Integer> from, Endpoint<Integer> to, int step) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(), step);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     */
+    public IntegerRange(int from, BoundType leftBoundType, int to,
+                        BoundType rightBoundType) {
+        this(from, leftBoundType, to, rightBoundType, DEFAULT_STEP.evaluate(from, to));
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     */
+    public IntegerRange(int from, BoundType leftBoundType, int to,
+                        BoundType rightBoundType, int step) {
+        this.leftEndpoint = Validate
+            .notNull(new Endpoint<Integer>(from, leftBoundType),
+                     "Left Endpoint argument must not be null");
+        this.rightEndpoint = Validate
+            .notNull(new Endpoint<Integer>(to, rightBoundType),
+                     "Right Endpoint argument must not be null");
+        this.step = step;
+        if (from != to && Integer.signum(step) != Integer.signum(to - from)) {
+            throw new IllegalArgumentException("Will never reach " + to
+                                               + " from " + from
+                                               + " using step " + step);
+        }
+        if (this.leftEndpoint.getBoundType() == BoundType.CLOSED) {
+            this.currentValue = this.leftEndpoint.getValue();
+        } else {
+            this.currentValue = this.leftEndpoint.getValue() + this.step;
+        }
+    }
+
+    // range methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Integer> getLeftEndpoint() {
+        return this.leftEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Integer> getRightEndpoint() {
+        return this.rightEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Integer getStep() {
+        return this.step;
+    }
+
+    // iterable, iterator methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasNext() {
+        final int to = this.rightEndpoint.getValue();
+        if (step < 0) {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue >= to;
+            } else {
+                return this.currentValue > to;
+            }
+        } else {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue <= to;
+            } else {
+                return this.currentValue < to;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Integer next() {
+        final int step = this.getStep();
+        final int r = this.currentValue;
+        this.currentValue += step;
+        return r;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Integer> iterator() {
+        return this;
+    }
+
+    // object methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "IntegerRange<" + this.leftEndpoint.toLeftString()
+                + ", " + this.rightEndpoint.toRightString()
+                + ", " + this.step + ">";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof IntegerRange)) {
+            return false;
+        }
+        IntegerRange that = (IntegerRange) obj;
+        return this.leftEndpoint.equals(that.leftEndpoint)
+                && this.rightEndpoint.equals(that.rightEndpoint)
+                && this.step == that.step;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int hash = "IntegerRange".hashCode();
+        hash <<= 2;
+        hash ^= this.leftEndpoint.getValue();
+        hash <<= 2;
+        hash ^= this.rightEndpoint.getValue();
+        hash <<= 2;
+        hash ^= this.step;
+        return hash;
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/LongRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/LongRange.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/LongRange.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/LongRange.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,295 @@
+/*
+ * 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.range;
+
+import java.util.Iterator;
+
+import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * A range of longs.
+ *
+ * @since 1.0
+ * @version $Revision: 1385335 $ $Date: 2012-09-16 15:08:31 -0300 (Sun, 16 Sep 2012) $
+ */
+public final class LongRange extends NumericRange<Long> implements Iterable<Long>, Iterator<Long> {
+    // attributes
+    //---------------------------------------------------------------
+
+    /**
+     * Left limit.
+     */
+    private final Endpoint<Long> leftEndpoint;
+
+    /**
+     * Right limit.
+     */
+    private final Endpoint<Long> rightEndpoint;
+
+    /**
+     * Increment step.
+     */
+    private final long step;
+
+    /**
+     * Current value.
+     */
+    private long currentValue;
+
+    /**
+     * Calculate default step.
+     */
+    public static final BinaryFunction<Long, Long, Long> DEFAULT_STEP = new BinaryFunction<Long, Long, Long>() {
+
+        public Long evaluate(Long left, Long right) {
+            return left > right ? -1L : 1L;
+        }
+    };
+
+    // constructors
+    // ---------------------------------------------------------------
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public LongRange(Number from, Number to) {
+        this(from.longValue(), to.longValue());
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public LongRange(Number from, Number to, Number step) {
+        this(from.longValue(), to.longValue(), step.longValue());
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public LongRange(long from, long to) {
+        this(from, to, DEFAULT_STEP.evaluate(from, to).longValue());
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public LongRange(long from, long to, long step) {
+        this(from, DEFAULT_LEFT_BOUND_TYPE, to, DEFAULT_RIGHT_BOUND_TYPE, step);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     */
+    public LongRange(Endpoint<Long> from, Endpoint<Long> to) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(),
+                DEFAULT_STEP.evaluate(from.getValue(), to.getValue()));
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public LongRange(Endpoint<Long> from, Endpoint<Long> to, int step) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(), step);
+    }
+
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     */
+    public LongRange(long from, BoundType leftBoundType, long to,
+                        BoundType rightBoundType) {
+        this(from, leftBoundType, to, rightBoundType, DEFAULT_STEP.evaluate(from, to));
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     */
+    public LongRange(Endpoint<Long> from, Endpoint<Long> to, long step) {
+        this(from.getValue(), from.getBoundType(), to.getValue(), to.getBoundType(), step);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     */
+    public LongRange(long from, BoundType leftBoundType, long to,
+                     BoundType rightBoundType, long step) {
+        this.leftEndpoint = Validate
+            .notNull(new Endpoint<Long>(from, leftBoundType),
+                     "Left Endpoint argument must not be null");
+        this.rightEndpoint = Validate
+            .notNull(new Endpoint<Long>(to, rightBoundType),
+                     "Right Endpoint argument must not be null");
+        this.step = step;
+        if (from != to && Long.signum(step) != Long.signum(to - from)) {
+            throw new IllegalArgumentException("Will never reach " + to
+                                               + " from " + from
+                                               + " using step " + step);
+        }
+        if (this.leftEndpoint.getBoundType() == BoundType.CLOSED) {
+            this.currentValue = this.leftEndpoint.getValue();
+        } else {
+            this.currentValue = this.leftEndpoint.getValue() + this.step;
+        }
+    }
+
+    // range methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Long> getLeftEndpoint() {
+        return this.leftEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Endpoint<Long> getRightEndpoint() {
+        return this.rightEndpoint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long getStep() {
+        return this.step;
+    }
+
+    // iterable, iterator methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasNext() {
+        final long to = this.rightEndpoint.getValue();
+        if (step < 0) {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue >= to;
+            } else {
+                return this.currentValue > to;
+            }
+        } else {
+            if (this.rightEndpoint.getBoundType() == BoundType.CLOSED) {
+                return this.currentValue <= to;
+            } else {
+                return this.currentValue < to;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long next() {
+        final long step = this.getStep();
+        final long r = this.currentValue;
+        this.currentValue += step;
+        return r;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Long> iterator() {
+        return this;
+    }
+
+    // object methods
+    // ---------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "LongRange<" + this.leftEndpoint.toLeftString() + ", "
+                + this.rightEndpoint.toRightString() + ", " + step + ">";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof LongRange)) {
+            return false;
+        }
+        LongRange that = (LongRange) obj;
+        return this.leftEndpoint.equals(that.leftEndpoint)
+                && this.rightEndpoint.equals(that.rightEndpoint)
+                && this.step == that.step;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int hash = "LongRange".hashCode();
+        hash <<= 2;
+        hash ^= this.leftEndpoint.getValue();
+        hash <<= 2;
+        hash ^= this.rightEndpoint.getValue();
+        hash <<= 2;
+        hash ^= this.step;
+        return hash;
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/NumericRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/NumericRange.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/NumericRange.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/NumericRange.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,113 @@
+/*
+ * 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.range;
+
+import java.util.Collection;
+
+/**
+ * A base class for numeric ranges. The elements within this range must be a
+ * <b>Number</b> and <b>Comparable</b>.
+ *
+ * @param <T> the type of numbers and step that are both a number and comparable
+ * @see org.apache.commons.functor.generator.range.IntegerRange
+ * @see org.apache.commons.functor.generator.range.LongRange
+ * @see org.apache.commons.functor.generator.range.FloatRange
+ * @see org.apache.commons.functor.generator.range.DoubleRange
+ * @see org.apache.commons.functor.generator.range.CharacterRange
+ * @since 0.1
+ * @version $Revision: $ $Date: $
+ */
+public abstract class NumericRange<T extends Number & Comparable<?>> implements Range<T, T> {
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        double leftValue = this.getLeftEndpoint().getValue().doubleValue();
+        double rightValue = this.getRightEndpoint().getValue().doubleValue();
+        boolean closedLeft = this.getLeftEndpoint().getBoundType() == BoundType.CLOSED;
+        boolean closedRight = this.getRightEndpoint().getBoundType() == BoundType.CLOSED;
+        if (!closedLeft && !closedRight
+             && this.getLeftEndpoint().equals(this.getRightEndpoint())) {
+            return Boolean.TRUE;
+        }
+        double step = this.getStep().doubleValue();
+        if (step > 0.0) {
+            double firstValue = closedLeft ? leftValue : leftValue + step;
+            return closedRight ? firstValue > rightValue
+                              : firstValue >= rightValue;
+        } else {
+            double firstValue = closedLeft ? leftValue : leftValue + step;
+            return closedRight ? firstValue < rightValue
+                              : firstValue <= rightValue;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean contains(T obj) {
+        if (obj == null) {
+            return Boolean.FALSE;
+        }
+        double leftValue = this.getLeftEndpoint().getValue().doubleValue();
+        double rightValue = this.getRightEndpoint().getValue().doubleValue();
+        boolean includeLeft = this.getLeftEndpoint().getBoundType() == BoundType.CLOSED;
+        boolean includeRight = this.getRightEndpoint().getBoundType() == BoundType.CLOSED;
+        double step = this.getStep().doubleValue();
+        double value = obj.doubleValue();
+
+        double firstValue = 0;
+        double lastValue = 0;
+
+        if (step < 0.0) {
+            firstValue = includeLeft ? leftValue : leftValue + step;
+            lastValue = includeRight ? rightValue : Math.nextUp(rightValue);
+            if (value > firstValue || value < lastValue) {
+                return Boolean.FALSE;
+            }
+        } else {
+            firstValue = includeLeft ? leftValue : leftValue + step;
+            lastValue = includeRight ? rightValue : rightValue
+                                                    - (rightValue - Math
+                                                        .nextUp(rightValue));
+            if (value < firstValue || value > lastValue) {
+                return Boolean.FALSE;
+            }
+        }
+        return ((value - firstValue) / step + 1) % 1.0 == 0.0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean containsAll(Collection<T> col) {
+        if (col == null || col.size() == 0) {
+            return Boolean.FALSE;
+        }
+        boolean r = Boolean.TRUE;
+        for (T t : col) {
+            if (!this.contains(t)) {
+                r = Boolean.FALSE;
+                break;
+            }
+        }
+        return r;
+    }
+
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Range.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Range.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Range.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Range.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.range;
+
+import java.util.Collection;
+
+
+/**
+ * Represent an interval of elements that varies from the <b>left limit</b>
+ * to the <b>right limit</b>. Each limit in this range is an {@link Endpoint
+ * Endpoint}. The left and the right limits can be <b>inclusive</b>
+ * (<b>bounded</b>, <b>closed</b>) or <b>exclusive</b> (<b>unbounded</b>,
+ * <b>open</b>).
+ * <p>
+ * The difference between each element within this range is called <b>step</b>.
+ * The step can be positive or negative, displaying whether the range elements
+ * are ascending or descending.
+ *
+ * @param <T> the type of elements held by this range.
+ * @param <S> the type of the step of this range.
+ * @see org.apache.commons.functor.generator.range.Endpoint
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public interface Range<T extends Comparable<?>, S extends Comparable<?>> {
+
+    /**
+     * Default left bound type.
+     */
+    BoundType DEFAULT_LEFT_BOUND_TYPE = BoundType.CLOSED;
+
+    /**
+     * Default right bound type.
+     */
+    BoundType DEFAULT_RIGHT_BOUND_TYPE = BoundType.OPEN;
+
+    /**
+     * Get the left limit of this range.
+     *
+     * @return Endpoint
+     */
+    Endpoint<T> getLeftEndpoint();
+
+    /**
+     * Get the right limit of this range.
+     *
+     * @return Endpoint
+     */
+    Endpoint<T> getRightEndpoint();
+
+    /**
+     * Get the step between elements of this range.
+     *
+     * @return Number
+     */
+    S getStep();
+
+    /**
+     * Returns <code>true</code> if this range is empty.
+     *
+     * @return <code>true</code> if this range is empty
+     */
+    boolean isEmpty();
+
+    /**
+     * Returns <code>true</code> if this range contains the specified element.
+     *
+     * @param obj element whose presence is being tested in this range
+     * @return <code>true</code> if this range contains the specified element
+     */
+    boolean contains(T obj);
+
+    /**
+     * Returns <code>true</code> is this range contains all of the elements in
+     * the specified collection.
+     *
+     * @param col collection to be checked for the containment in this range
+     * @return <code>true</code> if this range contains all of the elements in
+     * the specified collection
+     */
+    boolean containsAll(Collection<T> col);
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Ranges.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Ranges.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Ranges.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Ranges.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,388 @@
+/*
+ * 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.range;
+
+/**
+ * Range factory.
+ *
+ * @since 1.0
+ * @version $Revision: $ $Date: $
+ */
+public final class Ranges {
+
+    /**
+     * Hidden constructor as this only is a helper class with static methods.
+     */
+    private Ranges() {
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @return IntegerRange
+     */
+    public static IntegerRange integerRange(Number from, Number to) {
+        return new IntegerRange(from, to);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return IntegerRange
+     */
+    public static IntegerRange integerRange(Number from, Number to, Number step) {
+        return new IntegerRange(from, to, step);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @return IntegerRange
+     */
+    public static IntegerRange integerRange(int from, int to) {
+        return new IntegerRange(from, to);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return IntegerRange
+     */
+    public static IntegerRange integerRange(int from, int to, int step) {
+        return new IntegerRange(from, to, step);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     * @return IntegerRange
+     */
+    public static IntegerRange integerRange(int from, BoundType leftBoundType,
+                                            int to, BoundType rightBoundType,
+                                            int step) {
+        return new IntegerRange(from, leftBoundType, to, rightBoundType, step);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param leftEndpoint start
+     * @param rightEndpoint end
+     * @param step increment
+     * @return IntegerRange
+     */
+    public static IntegerRange integerRange(Endpoint<Integer> leftEndpoint,
+                                                Endpoint<Integer> rightEndpoint,
+                                                int step) {
+        return new IntegerRange(leftEndpoint, rightEndpoint, step);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @return LongRange
+     */
+    public static LongRange longRange(Number from, Number to) {
+        return new LongRange(from, to);
+    }
+
+    /**
+     * Create a new IntegerRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return LongRange
+     */
+    public static LongRange longRange(Number from, Number to, Number step) {
+        return new LongRange(from, to, step);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @return LongRange
+     */
+    public static LongRange longRange(long from, long to) {
+        return new LongRange(from, to);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return LongRange
+     */
+    public static LongRange longRange(long from, long to, long step) {
+        return new LongRange(from, to, step);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     * @return LongRange
+     */
+    public static LongRange longRange(long from, BoundType leftBoundType,
+                                      long to, BoundType rightBoundType,
+                                      long step) {
+        return new LongRange(from, leftBoundType, to, rightBoundType, step);
+    }
+
+    /**
+     * Create a new LongRange.
+     *
+     * @param leftEndpoint start
+     * @param rightEndpoint end
+     * @param step increment
+     * @return LongRange
+     */
+    public static LongRange longRange(Endpoint<Long> leftEndpoint,
+                                                Endpoint<Long> rightEndpoint,
+                                                long step) {
+        return new LongRange(leftEndpoint, rightEndpoint, step);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @return FloatRange
+     */
+    public static FloatRange floatRange(Number from, Number to) {
+        return new FloatRange(from, to);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return FloatRange
+     */
+    public static FloatRange floatRange(Number from, Number to, Number step) {
+        return new FloatRange(from, to, step);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @return FloatRange
+     */
+    public static FloatRange floatRange(float from, float to) {
+        return new FloatRange(from, to);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return FloatRange
+     */
+    public static FloatRange floatRange(float from, float to, float step) {
+        return new FloatRange(from, to, step);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     * @return FloatRange
+     */
+    public static FloatRange floatRange(float from, BoundType leftBoundType,
+                                        float to, BoundType rightBoundType,
+                                        float step) {
+        return new FloatRange(from, leftBoundType, to, rightBoundType, step);
+    }
+
+    /**
+     * Create a new FloatRange.
+     *
+     * @param leftEndpoint start
+     * @param rightEndpoint end
+     * @param step increment
+     * @return FloatRange
+     */
+    public static FloatRange floatRange(Endpoint<Float> leftEndpoint,
+                                                Endpoint<Float> rightEndpoint,
+                                                float step) {
+        return new FloatRange(leftEndpoint, rightEndpoint, step);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @return DoubleRange
+     */
+    public static DoubleRange doubleRange(Number from, Number to) {
+        return new DoubleRange(from, to);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return DoubleRange
+     */
+    public static DoubleRange doubleRange(Number from, Number to, Number step) {
+        return new DoubleRange(from, to, step);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @return DoubleRange
+     */
+    public static DoubleRange doubleRange(double from, double to) {
+        return new DoubleRange(from, to);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return DoubleRange
+     */
+    public static DoubleRange doubleRange(double from, double to, double step) {
+        return new DoubleRange(from, to, step);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     * @return DoubleRange
+     */
+    public static DoubleRange doubleRange(double from, BoundType leftBoundType,
+                                          double to, BoundType rightBoundType,
+                                          double step) {
+        return new DoubleRange(from, leftBoundType, to, rightBoundType, step);
+    }
+
+    /**
+     * Create a new DoubleRange.
+     *
+     * @param leftEndpoint start
+     * @param rightEndpoint end
+     * @param step increment
+     * @return DoubleRange
+     */
+    public static DoubleRange doubleRange(Endpoint<Double> leftEndpoint,
+                                                Endpoint<Double> rightEndpoint,
+                                                double step) {
+        return new DoubleRange(leftEndpoint, rightEndpoint, step);
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param to end
+     * @return CharacterRange
+     */
+    public static CharacterRange characterRange(char from, char to) {
+        return new CharacterRange(from, to);
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param to end
+     * @param step increment
+     * @return CharacterRange
+     */
+    public static CharacterRange characterRange(char from, char to, int step) {
+        return new CharacterRange(from, to, step);
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param from start
+     * @param leftBoundType type of left bound
+     * @param to end
+     * @param rightBoundType type of right bound
+     * @param step increment
+     * @return CharacterRange
+     */
+    public static CharacterRange characterRange(char from,
+                                                BoundType leftBoundType,
+                                                char to,
+                                                BoundType rightBoundType,
+                                                int step) {
+        return new CharacterRange(from, leftBoundType, to, rightBoundType, step);
+    }
+
+    /**
+     * Create a new CharacterRange.
+     *
+     * @param leftEndpoint start
+     * @param rightEndpoint end
+     * @param step increment
+     * @return CharacterRange
+     */
+    public static CharacterRange characterRange(Endpoint<Character> leftEndpoint,
+                                                Endpoint<Character> rightEndpoint,
+                                                int step) {
+        return new CharacterRange(leftEndpoint, rightEndpoint, step);
+    }
+}

Added: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/package-info.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/package-info.java?rev=1515264&view=auto
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/package-info.java (added)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/package-info.java Mon Aug 19 02:51:41 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.range;

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=1515264&r1=1515263&r2=1515264&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 Mon Aug 19 02:51:41 2013
@@ -34,7 +34,7 @@ import org.apache.commons.functor.genera
 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.apache.commons.functor.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() {
-        LoopGenerator<Integer> gen = new IntegerRange(1,5);
+        LoopGenerator<Integer> gen = IteratorToGeneratorAdapter.adapt(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/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=1515264&r1=1515263&r2=1515264&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 Mon Aug 19 02:51:41 2013
@@ -26,7 +26,8 @@ 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.range.IntegerRange;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.range.IntegerRange;
 import org.junit.Test;
 
 /**
@@ -102,7 +103,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 IntegerRange(0, 100001).toCollection());
+        List<Integer> largeList = (List<Integer>) (IteratorToGeneratorAdapter.adapt(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/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=1515264&r1=1515263&r2=1515264&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 Mon Aug 19 02:51:41 2013
@@ -25,7 +25,8 @@ import java.util.List;
 
 import org.apache.commons.functor.UnaryPredicate;
 import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.generator.range.IntegerRange;
+import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
+import org.apache.commons.functor.range.IntegerRange;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,7 +40,7 @@ public class TestFilteredGenerator
 
     @Before
     public void setUp() throws Exception {
-        wrappedGenerator = new IntegerRange(1, 10);
+        wrappedGenerator = IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10));
         filteredGenerator = new FilteredGenerator<Integer>(wrappedGenerator, isEven);
     }
 
@@ -70,13 +71,14 @@ public class TestFilteredGenerator
 
     @Test
     public void testEquals() {
-        Generator<Integer> anotherGenerate = new FilteredGenerator<Integer>(new IntegerRange(1, 10), isEven);
+        Generator<Integer> anotherGenerate = new FilteredGenerator<Integer>(
+                IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10)), isEven);
         assertEquals(filteredGenerator, filteredGenerator);
         assertEquals(filteredGenerator, anotherGenerate);
         assertTrue(!filteredGenerator.equals((FilteredGenerator<Integer>)null));
 
 		Generator<Integer> aGenerateWithADifferentPredicate = new FilteredGenerator<Integer>(
-			new IntegerRange(1, 10), new UnaryPredicate<Integer>() {
+	        IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10)), new UnaryPredicate<Integer>() {
 				public boolean test(Integer obj) {
 					return obj % 2 == 0;
 				}
@@ -84,7 +86,8 @@ public class TestFilteredGenerator
 
         assertTrue(!filteredGenerator.equals(aGenerateWithADifferentPredicate));
 
-        Generator<Integer> aGenerateWithADifferentWrapped = new FilteredGenerator<Integer>(new IntegerRange(1,11), isEven);
+        Generator<Integer> aGenerateWithADifferentWrapped = new FilteredGenerator<Integer>(
+                IteratorToGeneratorAdapter.adapt(new IntegerRange(1,11)), isEven);
         assertTrue(!filteredGenerator.equals(aGenerateWithADifferentWrapped));
     }
 

Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/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?rev=1515264&r1=1515263&r2=1515264&view=diff
==============================================================================
--- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java (original)
+++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java Mon Aug 19 02:51:41 2013
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertTru
 
 import org.apache.commons.functor.UnaryPredicate;
 import org.apache.commons.functor.generator.Generator;
-import org.apache.commons.functor.generator.range.IntegerRange;
+import org.apache.commons.functor.range.IntegerRange;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -35,7 +35,7 @@ public class TestGenerateUntil
 
     @Before
     public void setUp() throws Exception {
-        wrappedGenerator = new IntegerRange(1, 10);
+        wrappedGenerator = IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10));
         generateUntil = new GenerateUntil<Integer>(wrappedGenerator, isMoreThanFive);
     }
 
@@ -66,13 +66,14 @@ public class TestGenerateUntil
 
     @Test
     public void testEquals() {
-        Generator<Integer> anotherGenerate = new GenerateUntil<Integer>(new IntegerRange(1, 10), isMoreThanFive);
+        Generator<Integer> anotherGenerate = new GenerateUntil<Integer>(
+            IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10)), isMoreThanFive);
         assertEquals(generateUntil, generateUntil);
         assertEquals(generateUntil, anotherGenerate);
         assertTrue(!generateUntil.equals((GenerateUntil<Integer>)null));
 
 		Generator<Integer> aGenerateWithADifferentPredicate = new GenerateUntil<Integer>(
-				new IntegerRange(1, 10),
+		        IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10)),
 				new UnaryPredicate<Integer>() {
 				public boolean test(Integer obj) {
 					return obj > FIVE;
@@ -80,7 +81,8 @@ public class TestGenerateUntil
 			});
         assertTrue(!generateUntil.equals(aGenerateWithADifferentPredicate));
 
-        Generator<Integer> aGenerateWithADifferentWrapped = new GenerateUntil<Integer>(new IntegerRange(1,2), isMoreThanFive);
+        Generator<Integer> aGenerateWithADifferentWrapped = new GenerateUntil<Integer>(
+            IteratorToGeneratorAdapter.adapt(new IntegerRange(1,2)), isMoreThanFive);
         assertTrue(!generateUntil.equals(aGenerateWithADifferentWrapped));
     }
 



Mime
View raw message