com.github.cage
Class ObjectRoulette<T>

java.lang.Object
  extended by com.github.cage.ObjectRoulette<T>
Type Parameters:
T - the type of objects generated by this class
All Implemented Interfaces:
IGenerator<T>

public class ObjectRoulette<T>
extends Object
implements IGenerator<T>

An IGenerator implementation that returns a randomly chosen element from a predefined set of objects when next() is called. This class is thread safe.

Author:
akiraly

Constructor Summary
ObjectRoulette(Random rnd, T... candidates)
          Constructor.
 
Method Summary
 T[] getCandidates()
           
 T next()
          Returns an object with type T on every call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectRoulette

public ObjectRoulette(Random rnd,
                      T... candidates)
Constructor.

Parameters:
rnd - random generator to be used, can be null
candidates - the set of objects to choose from; not null, not empty
Method Detail

next

public T next()
Description copied from interface: IGenerator
Returns an object with type T on every call. The returned object does not have to be a new instance.

Specified by:
next in interface IGenerator<T>
Returns:
generated object

getCandidates

public T[] getCandidates()
Returns:
the set of objects to choose from


Copyright © 2011. All Rights Reserved.