Example usage for com.google.common.collect Ordering leastOf

List of usage examples for com.google.common.collect Ordering leastOf

Introduction

In this page you can find the example usage for com.google.common.collect Ordering leastOf.

Prototype

public <E extends T> List<E> leastOf(Iterator<E> elements, int k) 

Source Link

Document

Returns the k least elements from the given iterator according to this ordering, in order from least to greatest.

Usage

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);
}