org.flexgen.util
Class Chooser<T>

java.lang.Object
  extended by org.flexgen.util.Chooser<T>
Type Parameters:
T - The type of the options managed by this class.

public class Chooser<T>
extends java.lang.Object

Class implementing logic for chosing a single option from among a number of options with different probabilities.


Constructor Summary
Chooser(ImprovedRandom improvedRandom)
          Construct this class with the specified random number generator.
 
Method Summary
 void addOption(T option, int weight)
          Add an option that can be randomly chosesn.
 T choose()
          Randomly choose one option from the set of available options.
 boolean optionsAvailable()
          Determine if any options with any weight have been added.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Chooser

public Chooser(ImprovedRandom improvedRandom)
Construct this class with the specified random number generator.

Parameters:
improvedRandom - The random number generator to use.
Method Detail

addOption

public void addOption(T option,
                      int weight)
Add an option that can be randomly chosesn.

Parameters:
option - The option that can be randomly chosen.
weight - The probability of choosing the option.

choose

public T choose()
Randomly choose one option from the set of available options.

Returns:
The randomly chosen option.

optionsAvailable

public boolean optionsAvailable()
Determine if any options with any weight have been added.

Returns:
True if at least one option with non-zero weight has been added, false otherwise.


FlexGen Home

Get FlexGen at SourceForge.net. Fast, secure and Free Open Source software downloads

Copyright © 2009 - Jeffrey J. Weston <jjweston@gmail.com>

All rights reserved. Use is subject to license terms.