diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryChromosome.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryChromosome.java index 32fc94d058..d37d4dc6b9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryChromosome.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/BinaryChromosome.java @@ -67,7 +67,7 @@ protected void checkValidity(List chromosomeRepresentation) throws Inva */ public static List randomBinaryRepresentation(int length) { // random binary list - List rList= new ArrayList<> (length); + List rList= new ArrayList<>(length); for (int j=0; j extends AbstractListChromosome implem public RandomKey(final List representation) throws InvalidRepresentationException { super(representation); // store the sorted representation - List sortedRepr = new ArrayList<> (getRepresentation()); + List sortedRepr = new ArrayList<>(getRepresentation()); Collections.sort(sortedRepr); sortedRepresentation = Collections.unmodifiableList(sortedRepr); // store the permutation of [0,1,...,n-1] list for toString() and isSame() methods @@ -126,10 +126,10 @@ private static List decodeGeneric(final List sequence, List re } // do not modify the original representation - List reprCopy = new ArrayList<> (representation); + List reprCopy = new ArrayList<>(representation); // now find the indices in the original repr and use them for permuting - List res = new ArrayList<> (l); + List res = new ArrayList<>(l); for (int i=0; i List inducedPermutation(final List originalData, } int l = originalData.size(); - List origDataCopy = new ArrayList<> (originalData); + List origDataCopy = new ArrayList<>(originalData); Double[] res = new Double[l]; for (int i=0; i baseSequence(final int l) { - List baseSequence = new ArrayList<> (l); + List baseSequence = new ArrayList<>(l); for (int i=0; i repr = originalRk.getRepresentation(); int rInd = GeneticAlgorithm.getRandomGenerator().nextInt(repr.size()); - List newRepr = new ArrayList<> (repr); + List newRepr = new ArrayList<>(repr); newRepr.set(rInd, GeneticAlgorithm.getRandomGenerator().nextDouble()); return originalRk.newFixedLengthChromosome(newRepr); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/TournamentSelection.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/TournamentSelection.java index 847c1bb348..0d3fe76e6c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/TournamentSelection.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/TournamentSelection.java @@ -84,7 +84,7 @@ public Population nextGeneration() { }; // create a copy of the chromosome list - List chromosomes = new ArrayList<> (population.getChromosomes()); + List chromosomes = new ArrayList<>(population.getChromosomes()); for (int i=0; i> chooseInitialCenters(final Collection points) { // Convert to list for indexed access. Make it unmodifiable, since removal of items // would screw up the logic of this method. - final List pointList = Collections.unmodifiableList(new ArrayList<> (points)); + final List pointList = Collections.unmodifiableList(new ArrayList<>(points)); // The number of points in the list. final int numPoints = pointList.size(); @@ -386,7 +386,7 @@ List> chooseInitialCenters(final Collection points) { final T p = pointList.get(nextPointIndex); - resultSet.add(new CentroidCluster (p)); + resultSet.add(new CentroidCluster<>(p)); // Mark it as taken. taken[nextPointIndex] = true; diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/genetics/ListPopulationTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/genetics/ListPopulationTest.java index 8537f5c660..500e8428fb 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/genetics/ListPopulationTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/genetics/ListPopulationTest.java @@ -49,7 +49,7 @@ public double fitness() { } }; - ArrayList chromosomes = new ArrayList<> (); + ArrayList chromosomes = new ArrayList<>(); chromosomes.add(c1); chromosomes.add(c2); chromosomes.add(c3); @@ -67,7 +67,7 @@ public Population nextGeneration() { @Test public void testChromosomes() { - final ArrayList chromosomes = new ArrayList<> (); + final ArrayList chromosomes = new ArrayList<>(); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); @@ -115,7 +115,7 @@ public Population nextGeneration() { @Test(expected = NotPositiveException.class) public void testChromosomeListConstructorPopulationLimitNotPositive() { - final ArrayList chromosomes = new ArrayList<> (); + final ArrayList chromosomes = new ArrayList<>(); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); new ListPopulation(chromosomes, -10) { @Override @@ -128,7 +128,7 @@ public Population nextGeneration() { @Test(expected = NumberIsTooLargeException.class) public void testConstructorListOfChromosomesBiggerThanPopulationSize() { - final ArrayList chromosomes = new ArrayList<> (); + final ArrayList chromosomes = new ArrayList<>(); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); @@ -143,7 +143,7 @@ public Population nextGeneration() { @Test(expected=NumberIsTooLargeException.class) public void testAddTooManyChromosomes() { - final ArrayList chromosomes = new ArrayList<> (); + final ArrayList chromosomes = new ArrayList<>(); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); @@ -201,7 +201,7 @@ public Population nextGeneration() { @Test(expected=NumberIsTooSmallException.class) public void testSetPopulationLimitTooSmall() { - final ArrayList chromosomes = new ArrayList<> (); + final ArrayList chromosomes = new ArrayList<>(); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));