IndividualUtils { public static Individual getBestIndividual(Population[] populations){ Individual globalBest = null; Individual currentBest; if (populations != null){ for (Population population : populations){ currentBest = population.getBestIndividual(); if (globalBest == null){ globalBest = currentBest; } else if (currentBest != null && currentBest.getValue() < globalBest.getValue()){ globalBest = currentBest; } } } return globalBest; }  static Individual[] makeCopy(Individual[] sourceIndividuals, int birthday); static Individual getBestIndividual(Population[] populations); static Individual[] getAllIndividuals(Population[] populations); static Individual[] getIndividuals(Population[] populations, int maxIndexExclusive);  }
@Test public void testGetBestIndividual(){ Individual ind1 = new SimpleIndividual(0, 1.0, null); ind1.setValue(4.0); Individual ind2 = new SimpleIndividual(0, 1.0, null); ind2.setValue(1.0); Individual ind3 = new SimpleIndividual(0, 1.0, null); ind3.setValue(2.0); Population[] inputPopulations = new Population[]{new SimplePopulation(new Individual[]{ind1}), new SimplePopulation(new Individual[]{ind2}), new SimplePopulation(new Individual[]{ind3})}; Individual bestIndividual = IndividualUtils.getBestIndividual(inputPopulations); assertNotNull(bestIndividual); assertSame(ind2, bestIndividual); }