Skip to content

Commit

Permalink
CheckStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles Sadowski committed Aug 24, 2024
1 parent 7b0e1a0 commit 9d54ae1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void checkValidity(List<Integer> chromosomeRepresentation) throws Inva
*/
public static List<Integer> randomBinaryRepresentation(int length) {
// random binary list
List<Integer> rList= new ArrayList<> (length);
List<Integer> rList= new ArrayList<>(length);
for (int j=0; j<length; j++) {
rList.add(GeneticAlgorithm.getRandomGenerator().nextInt(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public abstract class RandomKey<T> extends AbstractListChromosome<Double> implem
public RandomKey(final List<Double> representation) throws InvalidRepresentationException {
super(representation);
// store the sorted representation
List<Double> sortedRepr = new ArrayList<> (getRepresentation());
List<Double> 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
Expand Down Expand Up @@ -126,10 +126,10 @@ private static <S> List<S> decodeGeneric(final List<S> sequence, List<Double> re
}

// do not modify the original representation
List<Double> reprCopy = new ArrayList<> (representation);
List<Double> reprCopy = new ArrayList<>(representation);

// now find the indices in the original repr and use them for permuting
List<S> res = new ArrayList<> (l);
List<S> res = new ArrayList<>(l);
for (int i=0; i<l; i++) {
int index = reprCopy.indexOf(sortedRepr.get(i));
res.add(sequence.get(index));
Expand Down Expand Up @@ -264,7 +264,7 @@ public static <S> List<Double> inducedPermutation(final List<S> originalData,
}
int l = originalData.size();

List<S> origDataCopy = new ArrayList<> (originalData);
List<S> origDataCopy = new ArrayList<>(originalData);

Double[] res = new Double[l];
for (int i=0; i<l; i++) {
Expand All @@ -291,7 +291,7 @@ public String toString() {
* @return list of integers from 0 to l-1
*/
private static List<Integer> baseSequence(final int l) {
List<Integer> baseSequence = new ArrayList<> (l);
List<Integer> baseSequence = new ArrayList<>(l);
for (int i=0; i<l; i++) {
baseSequence.add(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Chromosome mutate(final Chromosome original) throws MathIllegalArgumentEx
List<Double> repr = originalRk.getRepresentation();
int rInd = GeneticAlgorithm.getRandomGenerator().nextInt(repr.size());

List<Double> newRepr = new ArrayList<> (repr);
List<Double> newRepr = new ArrayList<>(repr);
newRepr.set(rInd, GeneticAlgorithm.getRandomGenerator().nextDouble());

return originalRk.newFixedLengthChromosome(newRepr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Population nextGeneration() {
};

// create a copy of the chromosome list
List<Chromosome> chromosomes = new ArrayList<> (population.getChromosomes());
List<Chromosome> chromosomes = new ArrayList<>(population.getChromosomes());
for (int i=0; i<this.arity; i++) {
// select a random individual and add it to the tournament
int rind = GeneticAlgorithm.getRandomGenerator().nextInt(chromosomes.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ List<CentroidCluster<T>> chooseInitialCenters(final Collection<T> points) {

// Convert to list for indexed access. Make it unmodifiable, since removal of items
// would screw up the logic of this method.
final List<T> pointList = Collections.unmodifiableList(new ArrayList<> (points));
final List<T> pointList = Collections.unmodifiableList(new ArrayList<>(points));

// The number of points in the list.
final int numPoints = pointList.size();
Expand Down Expand Up @@ -386,7 +386,7 @@ List<CentroidCluster<T>> chooseInitialCenters(final Collection<T> points) {

final T p = pointList.get(nextPointIndex);

resultSet.add(new CentroidCluster<T> (p));
resultSet.add(new CentroidCluster<>(p));

// Mark it as taken.
taken[nextPointIndex] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public double fitness() {
}
};

ArrayList<Chromosome> chromosomes = new ArrayList<> ();
ArrayList<Chromosome> chromosomes = new ArrayList<>();
chromosomes.add(c1);
chromosomes.add(c2);
chromosomes.add(c3);
Expand All @@ -67,7 +67,7 @@ public Population nextGeneration() {

@Test
public void testChromosomes() {
final ArrayList<Chromosome> chromosomes = new ArrayList<> ();
final ArrayList<Chromosome> chromosomes = new ArrayList<>();
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
Expand Down Expand Up @@ -115,7 +115,7 @@ public Population nextGeneration() {

@Test(expected = NotPositiveException.class)
public void testChromosomeListConstructorPopulationLimitNotPositive() {
final ArrayList<Chromosome> chromosomes = new ArrayList<> ();
final ArrayList<Chromosome> chromosomes = new ArrayList<>();
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
new ListPopulation(chromosomes, -10) {
@Override
Expand All @@ -128,7 +128,7 @@ public Population nextGeneration() {

@Test(expected = NumberIsTooLargeException.class)
public void testConstructorListOfChromosomesBiggerThanPopulationSize() {
final ArrayList<Chromosome> chromosomes = new ArrayList<> ();
final ArrayList<Chromosome> chromosomes = new ArrayList<>();
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
Expand All @@ -143,7 +143,7 @@ public Population nextGeneration() {

@Test(expected=NumberIsTooLargeException.class)
public void testAddTooManyChromosomes() {
final ArrayList<Chromosome> chromosomes = new ArrayList<> ();
final ArrayList<Chromosome> chromosomes = new ArrayList<>();
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
Expand Down Expand Up @@ -201,7 +201,7 @@ public Population nextGeneration() {

@Test(expected=NumberIsTooSmallException.class)
public void testSetPopulationLimitTooSmall() {
final ArrayList<Chromosome> chromosomes = new ArrayList<> ();
final ArrayList<Chromosome> chromosomes = new ArrayList<>();
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
Expand Down

0 comments on commit 9d54ae1

Please sign in to comment.