List of usage examples for com.google.common.collect Ordering leastOf
public <E extends T> List<E> leastOf(Iterator<E> elements, int k)
From source file:msi.gama.metamodel.topology.grid.GamaSpatialMatrix.java
@Override public Collection<IAgent> firstAtDistance(final IScope scope, final IShape source, final double dist, final IAgentFilter f, int number, Collection<IAgent> alreadyChosen) { final double exp = dist * Maths.SQRT2; final Envelope3D env = new Envelope3D(source.getEnvelope()); env.expandBy(exp);//from w ww.j a v a 2 s .com final Set<IAgent> shapes = allInEnvelope(scope, source, env, f, false); shapes.removeAll(alreadyChosen); if (shapes.size() <= number) return shapes; boolean gridSpe = (f.getSpecies() != null) && (f.getSpecies().isGrid()); final Ordering<IShape> ordering = gridSpe ? Ordering.natural().onResultOf(input -> source.euclidianDistanceTo(input.getLocation())) : Ordering.natural().onResultOf(input -> source.euclidianDistanceTo(input)); return ordering.leastOf(shapes, number); }