package jsprit.core.util;

import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute;

import java.util.Collection;
import java.util.Random;

/**
 * Created by schroeder on 14/01/15.
 */
public class RandomUtils {

    public static VehicleRoute nextRoute(Collection<VehicleRoute> routes, Random random){
        return nextItem(routes,random);
    }

    public static Job nextJob(Collection<Job> jobs, Random random){
        return nextItem(jobs,random);
    }

    public static <T> T nextItem(Collection<T> items, Random random){
        int randomIndex = random.nextInt(items.size());
        int count = 0;
        for(T item : items){
            if(count == randomIndex) return item;
            count++;
        }
        return null;
    }

}

@@ -142,16 +142,39 @@
 ection;%0A
+import java.util.List;%0A
 import j
@@ -190,16 +190,16 @@
 Random;%0A
-
 %0A/**%0A * 
@@ -506,32 +506,139 @@
 random);%0A    %7D%0A%0A
+    public static Job nextJob(List%3CJob%3E jobs, Random random)%7B%0A        return nextItem(jobs,random);%0A    %7D%0A%0A
     public stati
@@ -880,16 +880,16 @@
       %7D%0A
-
         
@@ -908,10 +908,176 @@
 %0A    %7D%0A%0A
+    public static %3CT%3E T nextItem(List%3CT%3E items, Random random)%7B%0A        int randomIndex = random.nextInt(items.size());%0A        return items.get(randomIndex);%0A    %7D%0A%0A
 %7D%0A

enhance RandomUtils