You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/04/12 20:32:54 UTC
svn commit: r1325427 - in /commons/proper/math/trunk/src: changes/changes.xml
main/java/org/apache/commons/math3/genetics/ListPopulation.java
test/java/org/apache/commons/math3/genetics/ListPopulationTest.java
Author: tn
Date: Thu Apr 12 18:32:53 2012
New Revision: 1325427
URL: http://svn.apache.org/viewvc?rev=1325427&view=rev
Log:
[MATH-779] Fixed iterator() method in ListPopulation to return an iterator of the unmodifiable list, thanks to Reid Hochstedler.
Modified:
commons/proper/math/trunk/src/changes/changes.xml
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/genetics/ListPopulationTest.java
Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1325427&r1=1325426&r2=1325427&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Thu Apr 12 18:32:53 2012
@@ -52,6 +52,12 @@ If the output is not quite correct, chec
<body>
<release version="3.1" date="TBD" description="
">
+ <action dev="tn" type="fix" issue="MATH-779" due-to="Reid Hochstedler">
+ Fixed ListPopulation#iterator to return an unmodifiable iterator.
+ </action>
+ <action dev="tn" type="fix" issue="MATH-775" due-to="Reid Hochstedler">
+ Cleanup of ListPopulation to consistently enforce the population limit.
+ </action>
<action dev="tn" type="fix" issue="MATH-776" due-to="Reid Hochstedler">
Use same range check in constructor for ElitisticListPopulation as in corresponding setter.
</action>
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java?rev=1325427&r1=1325426&r2=1325427&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java Thu Apr 12 18:32:53 2012
@@ -200,11 +200,12 @@ public abstract class ListPopulation imp
}
/**
- * Chromosome list iterator
+ * Returns an iterator over the unmodifiable list of chromosomes.
+ * <p>Any call to {@link Iterator#remove()} will result in a {@link UnsupportedOperationException}.</p>
*
* @return chromosome iterator
*/
public Iterator<Chromosome> iterator() {
- return chromosomes.iterator();
+ return getChromosomes().iterator();
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/genetics/ListPopulationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/genetics/ListPopulationTest.java?rev=1325427&r1=1325426&r2=1325427&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/genetics/ListPopulationTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/genetics/ListPopulationTest.java Thu Apr 12 18:32:53 2012
@@ -18,6 +18,7 @@ package org.apache.commons.math3.genetic
import java.util.ArrayList;
+import java.util.Iterator;
import org.apache.commons.math3.exception.NotPositiveException;
import org.apache.commons.math3.exception.NumberIsTooLargeException;
@@ -163,6 +164,29 @@ public class ListPopulationTest {
}
}
+ @Test(expected = UnsupportedOperationException.class)
+ public void testIterator() {
+ final ArrayList<Chromosome> chromosomes = new ArrayList<Chromosome>();
+ chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
+ chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
+ chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
+
+ final ListPopulation population = new ListPopulation(10) {
+ public Population nextGeneration() {
+ // not important
+ return null;
+ }
+ };
+
+ population.addChromosomes(chromosomes);
+
+ final Iterator<Chromosome> iter = population.iterator();
+ while (iter.hasNext()) {
+ iter.next();
+ iter.remove();
+ }
+ }
+
@Test(expected=NumberIsTooSmallException.class)
public void testSetPopulationLimitTooSmall() {
final ArrayList<Chromosome> chromosomes = new ArrayList<Chromosome> ();