PopulationUtils { public static Population[] appendPopulation(Population[] populations, Population populationToAppend, boolean appendAtTheEnd){ Population[] result = null; if (populations != null){ if (populationToAppend != null){ result = new Population[populations.length + 1]; int startIndex = 0; if (appendAtTheEnd){ startIndex = 0; result[result.length - 1] = populationToAppend; } else { startIndex = 1; result[0] = populationToAppend; } for (Population population : populations){ result[startIndex++] = population; } } else { result = populations; } } else if (populationToAppend != null) { result = new Population[]{populationToAppend}; } return result; }  static Population concatenate(Population[] populations, PopulationFactory populationFactory); static Population concatenate(Population[] populations, PopulationFactory populationFactory, int maxIndexExclusive); static Population[] appendPopulation(Population[] populations, Population populationToAppend, boolean appendAtTheEnd); static int sumSizes(Population[] populations); static int sumSizes(Population[] populations, int maxIndexExclusive);  }
@Test public void testAppendPopulation1(){ Population[] inputPopulations = new Population[]{new SimplePopulation(), new SimplePopulation(), new SimplePopulation() }; Population populationToAppend = new SimplePopulation(); Population[] results = PopulationUtils.appendPopulation(inputPopulations, populationToAppend, true); assertEquals(4, results.length); assertSame(inputPopulations[0], results[0]); assertSame(inputPopulations[1], results[1]); assertSame(inputPopulations[2], results[2]); assertSame(populationToAppend, results[3]); }
@Test public void testAppendPopulation2(){ Population[] inputPopulations = new Population[]{new SimplePopulation(), new SimplePopulation(), new SimplePopulation() }; Population populationToAppend = new SimplePopulation(); Population[] results = PopulationUtils.appendPopulation(inputPopulations, populationToAppend, false); assertEquals(4, results.length); assertSame(populationToAppend, results[0]); assertSame(inputPopulations[0], results[1]); assertSame(inputPopulations[1], results[2]); assertSame(inputPopulations[2], results[3]); }
@Test public void testAppendPopulation3(){ Population populationToAppend = new SimplePopulation(); Population[] results = PopulationUtils.appendPopulation(null, populationToAppend, true); assertEquals(1, results.length); assertSame(populationToAppend, results[0]); }
@Test public void testAppendPopulation4(){ Population populationToAppend = new SimplePopulation(); Population[] results = PopulationUtils.appendPopulation(null, populationToAppend, false); assertEquals(1, results.length); assertSame(populationToAppend, results[0]); }
@Test public void testAppendPopulation5(){ Population[] results = PopulationUtils.appendPopulation(null, null, true); assertEquals(null, results); }