Class EnumRandomizer<E extends java.lang.Enum<E>>
- java.lang.Object
-
- org.jeasy.random.randomizers.AbstractRandomizer<E>
-
- org.jeasy.random.randomizers.misc.EnumRandomizer<E>
-
- Type Parameters:
E- the type of elements in the enumeration
- All Implemented Interfaces:
Randomizer<E>
public class EnumRandomizer<E extends java.lang.Enum<E>> extends AbstractRandomizer<E>
ARandomizerthat generates a random value from a givenEnum.- Author:
- Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
-
-
Field Summary
-
Fields inherited from class org.jeasy.random.randomizers.AbstractRandomizer
random
-
-
Constructor Summary
Constructors Constructor Description EnumRandomizer(java.lang.Class<E> enumeration)Create a newEnumRandomizer.EnumRandomizer(java.lang.Class<E> enumeration, long seed)Create a newEnumRandomizer.EnumRandomizer(java.lang.Class<E> enumeration, E... excludedValues)Create a newEnumRandomizer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EgetRandomValue()Get a random value within an enumeration or an enumeration subset (when values are excluded)-
Methods inherited from class org.jeasy.random.randomizers.AbstractRandomizer
getPredefinedValuesOf, nextDouble, toString
-
-
-
-
Constructor Detail
-
EnumRandomizer
public EnumRandomizer(java.lang.Class<E> enumeration)
Create a newEnumRandomizer.- Parameters:
enumeration- the enumeration from which this randomizer will generate random values
-
EnumRandomizer
public EnumRandomizer(java.lang.Class<E> enumeration, long seed)
Create a newEnumRandomizer.- Parameters:
enumeration- the enumeration from which this randomizer will generate random valuesseed- the initial seed
-
EnumRandomizer
public EnumRandomizer(java.lang.Class<E> enumeration, E... excludedValues) throws java.lang.IllegalArgumentException
Create a newEnumRandomizer.- Parameters:
enumeration- the enumeration from which this randomizer will generate random valuesexcludedValues- the values to exclude from random picking- Throws:
java.lang.IllegalArgumentException- when excludedValues contains all enumeration values, ie all elements from the enumeration are excluded
-
-
Method Detail
-
getRandomValue
public E getRandomValue()
Get a random value within an enumeration or an enumeration subset (when values are excluded)- Returns:
- a random value within the enumeration
-
-