class SlavePriorities {

    public static SlavePriority roundRobin()
    {
        return new SlavePriority()
        {
            final AtomicInteger index = new AtomicInteger();

            @Override
            public Iterable<Slave> prioritize( final Iterable<Slave> slaves )
            {
                final List<Slave> slaveList = sortSlaves( slaves, true );
                if ( slaveList.isEmpty() )
                {
                    return Iterables.empty();
                }
                return () -> new PrefetchingIterator<Slave>()
                {
                    private int start = index.getAndIncrement() % slaveList.size();
                    private int count;

                    @Override
                    protected Slave fetchNextOrNull()
                    {
                        int id = count++;
                        return id <= slaveList.size() ? slaveList.get( (start + id) % slaveList.size() ) : null;
                    }
                };
            }
        };
    }

    private  SlavePriorities();

}