All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.qatools.gridrouter.config.RandomHostSelectionStrategy Maven / Gradle / Ivy

There is a newer version: 1.31
Show newest version
package ru.qatools.gridrouter.config;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.nCopies;
import static java.util.Collections.shuffle;

/**
 * @author Innokenty Shuvalov [email protected]
 */
public class RandomHostSelectionStrategy implements HostSelectionStrategy {

    protected  T selectRandom(List elements) {
        List copies = new ArrayList<>();
        for (T element : elements) {
            copies.addAll(nCopies(element.getCount(), element));
        }
        shuffle(copies);
        return copies.get(0);
    }

    @Override
    public Region selectRegion(List allRegions, List unvisitedRegions) {
        return selectRandom(unvisitedRegions);
    }

    @Override
    public Host selectHost(List hosts) {
        return selectRandom(hosts);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy