cosmic.util
Class Adjudicator

java.lang.Object
  |
  +--cosmic.util.Adjudicator

public class Adjudicator
extends java.lang.Object

A class for choosing the 'best' among several candidates according to some user-supplied criterion, with ties resolved randomly. Author: James.A.Marshall@imperial.ac.uk


Field Summary
static int dropAll
          Constant to denote dropping all candidates when releasing Adjudicator instance
static int dropLosers
          Constant to denote dropping losing candidates when releasing Adjudicator instance
static int dropNone
          Constant to denote dropping no candidates when releasing Adjudicator instance
private  double mBestDouble
          The best double value found so far
private  int mBestInt
          The best int value found so far
private  java.util.LinkedList mCandidates
          The list of candidates to be chosen between
private  java.lang.Class mClass
          The class of candidates to be chosen between
private  boolean mLowestWins
          The flag that indicates if the winner is the lowest or highest value (true = lowest, false = highest)
private  swarm.objectbase.MessageProbe mMessageProbe
          The message probe used to determine the winner
private  java.lang.String mMessageProbeString
          The name of the message probe used to determine the winner
private static swarm.random.UniformIntegerDist msDistribution
          Random number generator for all instances of adjudicator
private static java.util.LinkedList msInstances
          Instances of the Adjudicator class
private static java.util.LinkedList msUnusedInstances
          Unused instances of the Adjudicator class
private  java.util.LinkedList mTiedCandidates
          The list of candidates that are tied
private  boolean mUseable
          The flag that indicates if the instantiation is useable
private  java.lang.Object mWinner
          The winner of the adjudication
 
Constructor Summary
private Adjudicator()
          Private constructor for the class Adjudicator
 
Method Summary
 void addCandidate(java.lang.Object candidate)
          Adds a candidate for selection
static Adjudicator getFreeInstance(java.lang.String messageProbeString, boolean lowestWins)
          Gets an unused instance of the class Adjudicator for adjudication according to the supplied criteria
 ImmutableIterator getIteratorOnCandidates()
          Gets an iterator over the candidates in the Adjudicator
 java.lang.Object getWinner()
          Gets the winner of the adjudication (multiple calls will all return the same winner)
 void releaseInstance(int dropPolicy)
          Releases the Adjudicator instantiation for re-use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mClass

private java.lang.Class mClass
The class of candidates to be chosen between


mMessageProbe

private swarm.objectbase.MessageProbe mMessageProbe
The message probe used to determine the winner


mMessageProbeString

private java.lang.String mMessageProbeString
The name of the message probe used to determine the winner


mLowestWins

private boolean mLowestWins
The flag that indicates if the winner is the lowest or highest value (true = lowest, false = highest)


mBestInt

private int mBestInt
The best int value found so far


mBestDouble

private double mBestDouble
The best double value found so far


mCandidates

private java.util.LinkedList mCandidates
The list of candidates to be chosen between


mTiedCandidates

private java.util.LinkedList mTiedCandidates
The list of candidates that are tied


mWinner

private java.lang.Object mWinner
The winner of the adjudication


mUseable

private boolean mUseable
The flag that indicates if the instantiation is useable


msInstances

private static java.util.LinkedList msInstances
Instances of the Adjudicator class


msUnusedInstances

private static java.util.LinkedList msUnusedInstances
Unused instances of the Adjudicator class


msDistribution

private static swarm.random.UniformIntegerDist msDistribution
Random number generator for all instances of adjudicator


dropNone

public static final int dropNone
Constant to denote dropping no candidates when releasing Adjudicator instance

See Also:
Constant Field Values

dropLosers

public static final int dropLosers
Constant to denote dropping losing candidates when releasing Adjudicator instance

See Also:
Constant Field Values

dropAll

public static final int dropAll
Constant to denote dropping all candidates when releasing Adjudicator instance

See Also:
Constant Field Values
Constructor Detail

Adjudicator

private Adjudicator()
Private constructor for the class Adjudicator

Method Detail

addCandidate

public void addCandidate(java.lang.Object candidate)
Adds a candidate for selection

Parameters:
candidate - (!= null)
Returns:
void
Throws:
java.lang.RuntimeException - if instance is not useable
java.lang.RuntimeException - if called after getWinner
java.lang.RuntimeException - if message probe specified in constructor has unhandled return type (only int and double are valid)
java.lang.RuntimeException - if candidate does not respond to message specified in constructor
java.lang.RuntimeException - if called without first calling newAdjudication

getIteratorOnCandidates

public ImmutableIterator getIteratorOnCandidates()
Gets an iterator over the candidates in the Adjudicator

Returns:
Iterator over candidates in Adjudicator
Throws:
java.lang.RuntimeException - if instance is not useable
java.lang.RuntimeException - if called before getWinner

getWinner

public java.lang.Object getWinner()
Gets the winner of the adjudication (multiple calls will all return the same winner)

Returns:
The winner of the adjudication
Throws:
java.lang.RuntimeException - if instance is not useable
java.lang.RuntimeException - if called without first calling newAdjudication

releaseInstance

public void releaseInstance(int dropPolicy)
Releases the Adjudicator instantiation for re-use

Parameters:
dropPolicy - (dropNone || dropLosers || dropAll)
Returns:
void
Throws:
java.lang.RuntimeException - if instance is not useable

getFreeInstance

public static Adjudicator getFreeInstance(java.lang.String messageProbeString,
                                          boolean lowestWins)
Gets an unused instance of the class Adjudicator for adjudication according to the supplied criteria

Parameters:
messageProbeString - - the name of the function to be used in evaluating the winner
lowestWins - - true indicates the lowest value wins, false indicates the highest value wins
Returns:
Unused instance of Adjudicator