int (@NotNull Differ differ, int newPoolSize) { List<IntPair> ranges = new ArrayList<>(myGensPool.size()); int i = 0; for (final Gens gens : myGensPool) { int range = differ.getDifference(gens); ranges.add(new IntPair(range, i++)); if (range == 0) { myAge = GEN_COUNT; newPoolSize = 1; break; } } ranges.sort(Comparator.comparingInt(o -> o.first)); final ArrayList<Gens> gensPool = new ArrayList<>(newPoolSize); int count = 0; int worseForward = 0; for (IntPair pair : ranges) { if (count >= newPoolSize) { break; } Gens gens = myGensPool.get(pair.second); gensPool.add(gens); ++count; worseForward = pair.first; } myGensPool = gensPool; return worseForward; }