Package org.instancio.generators
Class Generators
- java.lang.Object
-
- org.instancio.generators.Generators
-
public class Generators extends Object
This class provides access to built-in generators.It can be used to customise random values generated by built-in generators. This includes numeric, collection sizes, string lengths, etc.
-
-
Constructor Summary
Constructors Constructor Description Generators(GeneratorContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> ArrayGeneratorSpec<T>
array()
Customises generated arrays.AtomicGenerators
atomic()
Provides access to atomic generators.NumberGeneratorSpec<Byte>
bytes()
Customises generatedByte
values.<T> CollectionGeneratorSpec<T>
collection()
Customises generated collections.NumberGeneratorSpec<Double>
doubles()
Customises generatedDouble
values.NumberGeneratorSpec<Float>
floats()
Customises generatedFloat
values.static String
getApiMethod(Class<?> generatorSpec)
Returns the public API method for the given generator spec class.NumberGeneratorSpec<Integer>
ints()
Customises generatedInteger
values.NumberGeneratorSpec<Long>
longs()
Customises generatedLong
values.<K,V>
MapGeneratorSpec<K,V>map()
Customises generated maps.MathGenerators
math()
Return generators forjava.math
classes.<T> OneOfCollectionGeneratorSpec<T>
oneOf(Collection<T> choices)
Picks a random value from the given choices.<T> OneOfArrayGeneratorSpec<T>
oneOf(T... choices)
Picks a random value from the given choices.NumberGeneratorSpec<Short>
shorts()
Customises generatedShort
values.StringGeneratorSpec
string()
Customises generatedString
values.TemporalGenerators
temporal()
Provides access to temporal generators.TextGenerators
text()
Provides access to text generators.
-
-
-
Constructor Detail
-
Generators
public Generators(GeneratorContext context)
-
-
Method Detail
-
getApiMethod
public static String getApiMethod(Class<?> generatorSpec)
Returns the public API method for the given generator spec class.- Parameters:
generatorSpec
- whose API method to return- Returns:
- the public API method, for example
array()
for the array generator
-
string
public StringGeneratorSpec string()
Customises generatedString
values.- Returns:
- customised generator
-
bytes
public NumberGeneratorSpec<Byte> bytes()
Customises generatedByte
values.- Returns:
- customised generator
-
shorts
public NumberGeneratorSpec<Short> shorts()
Customises generatedShort
values.- Returns:
- customised generator
-
ints
public NumberGeneratorSpec<Integer> ints()
Customises generatedInteger
values.- Returns:
- customised generator
-
longs
public NumberGeneratorSpec<Long> longs()
Customises generatedLong
values.- Returns:
- customised generator
-
floats
public NumberGeneratorSpec<Float> floats()
Customises generatedFloat
values.- Returns:
- customised generator
-
doubles
public NumberGeneratorSpec<Double> doubles()
Customises generatedDouble
values.- Returns:
- customised generator
-
math
public MathGenerators math()
Return generators forjava.math
classes.- Returns:
- built-in generators for
java.math
classes.
-
oneOf
@SafeVarargs public final <T> OneOfArrayGeneratorSpec<T> oneOf(T... choices)
Picks a random value from the given choices.- Type Parameters:
T
- element type- Parameters:
choices
- to choose from- Returns:
- generator for making a selection
-
oneOf
public final <T> OneOfCollectionGeneratorSpec<T> oneOf(Collection<T> choices)
Picks a random value from the given choices.- Type Parameters:
T
- element type- Parameters:
choices
- to choose from- Returns:
- generator for making a selection
-
array
public <T> ArrayGeneratorSpec<T> array()
Customises generated arrays.- Type Parameters:
T
- array component type- Returns:
- customised generator
-
collection
public <T> CollectionGeneratorSpec<T> collection()
Customises generated collections.- Type Parameters:
T
- element type- Returns:
- customised generator
-
map
public <K,V> MapGeneratorSpec<K,V> map()
Customises generated maps.- Type Parameters:
K
- key typeV
- value type- Returns:
- customised generator
-
atomic
public AtomicGenerators atomic()
Provides access to atomic generators.- Returns:
- built-in atomic generators
-
temporal
public TemporalGenerators temporal()
Provides access to temporal generators.- Returns:
- built-in temporal generators
-
text
public TextGenerators text()
Provides access to text generators.- Returns:
- built-in text generators
-
-