public ParetoFront<T> trim(
		final int size,
		final ElementComparator<? super T> comparator,
		final ElementDistance<? super T> distance,
		final ToIntFunction<? super T> dimension
	) {
		requireNonNull(comparator);
		requireNonNull(distance);
		requireNonNull(dimension);

		if (size() > size) {
			final double[] distances = Pareto.crowdingDistance(
				Seq.viewOf(_population),
				comparator,
				distance,
				dimension
			);
			final int[] indexes = ProxySorter.sort(distances);
			revert(indexes);

			final List<T> list = IntStream.of(indexes)
				.limit(size)
				.mapToObj(_population::get)
				.toList();

			_population.clear();
			_population.addAll(list);
		}

		return this;
	}
Trims {@code this} pareto front to the given size. The front elements are
sorted according to its crowding distance, and the elements which have
smaller distance to its neighbors are removed first.

{@snippet lang="java":
final ParetoFront<Vec<double[]>> front = new ParetoFront<>(Vec::dominance);
front.trim(10, Vec::compare, Vec::distance, Vec::length);
}
The example above reduces the given front to 10 elements.

@param size the number of front elements after the trim. If
       {@code size() <= size}, nothing is trimmed.
@param comparator the element comparator used for calculating the
       crowded distance
@param distance the element distance measure
@param dimension the number of vector elements of {@code T}
@return {@code this} trimmed pareto front
@throws NullPointerException if one of the objects is {@code null}
jenetics.ext/src/main/java/io/jenetics/ext/moea/ParetoFront.java