Permalink
Browse files

Refined random agent picking functionality Further minor clean up.

  • Loading branch information...
chrfrantz committed Mar 9, 2016
1 parent 127664e commit bf9185f3bd63d0864548cb520a719a674a412760
@@ -711,19 +711,33 @@ public static void sendGlobalBroadcast(MicroMessage message, boolean localBroadc
* @return List of randomly chosen agents; returns empty list if too little agents available in candidate list for picking.
*/
public static List<String> getRandomAgentsFromList(int numberOfTargets, ArrayList<String> inclusionList){
return getRandomAgentsFromList(numberOfTargets, inclusionList, false);
return getRandomAgentsFromList(numberOfTargets, inclusionList, null, false);
}
/**
* Returns randomly picked agents from list of given agents. Checks for agents' registration prior to
* picking.
* Returns exactly the requested number of agents (numberOfTargets) or none.
* @param numberOfTargets Number of targets to be picked
* @param inclusionList List from which agents are to be picked
* @param exclusionList List of agents (in inclusionList) that should not be picked. Ignored if null.
* @return List of randomly chosen agents; returns empty list if too little agents available in candidate list for picking.
*/
public static List<String> getRandomAgentsFromList(int numberOfTargets, ArrayList<String> inclusionList, ArrayList<String> exclusionList){
return getRandomAgentsFromList(numberOfTargets, inclusionList, exclusionList, false);
}
/**
* Returns randomly picked agents from list of given agents. Checks for agents' registration prior to
* picking.
* @param numberOfTargets Number of targets to be picked
* @param inclusionList List from which agents are to be picked
* @param exclusionList List of agents (in inclusionList) that should not be picked. Ignored if null.
* @param allowLessTargets Indicates if returning less than requested number of agents is permissible. If not, it returns
* empty list if insufficient agents available.
* @return List of randomly chosen agents; returns empty list if too little agents available in candidate list for picking.
*/
public static List<String> getRandomAgentsFromList(int numberOfTargets, ArrayList<String> inclusionList, boolean allowLessTargets){
public static List<String> getRandomAgentsFromList(int numberOfTargets, ArrayList<String> inclusionList, ArrayList<String> exclusionList, boolean allowLessTargets){
//list of delivered random number (no double pick)
ArrayList<String> deliveredRandoms = new ArrayList<String>();
@@ -750,6 +764,13 @@ public static void sendGlobalBroadcast(MicroMessage message, boolean localBroadc
}
}
//filter agents that are in exclusionList
if(exclusionList != null){
for(int i = 0; i < exclusionList.size(); i++){
inclusionList.remove(exclusionList.get(i));
}
}
//check if there are enough agents to pick after all
if(numberOfTargets > inclusionList.size()){
if(allowLessTargets){
@@ -1270,10 +1270,6 @@ public boolean containsCollection(Object object, boolean testForMap){
}
}
public boolean isCollection(Object object){
return object instanceof Collection<?>;
}
int previousLength = 0;
private StringBuffer calcStringPrefix(){

0 comments on commit bf9185f

Please sign in to comment.