I have a CSV file containing data which I read using a Bean Shell script and populate an ArrayList based upon it.Below is the code for it.
//Populate Beanshell script
import java.text.*;
import java.io.*;
import java.util.*;
ArrayList strList = new ArrayList();
try {
File file = new File("path/to/csv");
if (!file.exists()) {
throw new Exception ("ERROR: file not found");
}
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
while((line = bufRdr.readLine()) != null) {
strList.add(line);
}
bufRdr.close();
}
catch (Exception ex) {
IsSuccess = false;
log.error(ex.getMessage());
System.err.println(ex.getMessage());
}
catch (Throwable thex) {
System.err.println(thex.getMessage());
}
Now I want to utilize this data in a random manner so I am trying to use something like this
//Consumer bean shell script
//Not able to access strList since vars.put cannot store an object
Random rnd = new java.util.Random();
vars.put("TheValue",strList.get(rnd.nextInt(strList.size())));
But I am unable to do this because in vars.put I cannot store an array or a list,I can only store only primitive types.So there is no way in which I can access the populate function's ArrayList from an another BeanShell script.
How do I achieve randomization in this scenario since calling populate function each and every time is not good from a performance point of view.
vars?vars?