com.github.cage
Class ObjectRoulette<T>
java.lang.Object
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ObjectRoulette
public ObjectRoulette(Random rnd,
T... candidates)
- Constructor.
- Parameters:
rnd
- random generator to be used, can be nullcandidates
- the set of objects to choose from; not null, not empty
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.