Package org.instancio.generators
Interface ValueSpecs
- All Superinterfaces:
CommonGeneratorSpecs
- All Known Subinterfaces:
InstancioGenApi
Defines all built-in generators that are available
via the
Instancio.gen() method.- Since:
- 5.0.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleans()Generator forBooleanvalues.bytes()Generator forBytevalues.chars()Generator forCharactervalues.checksum()Provides access to checksum generators.doubles()Generator forDoublevalues.Generator for enum values.finance()Provides access to finance-related generators.floats()Generator forFloatvalues.hash()Generator for various types of hashes.id()Provides access to identifier generators.<T> IntervalSpec<T> intervalStarting(T startingValue) A spec for generating intervals of various types, such as numeric and temporal values.ints()Generator forIntegervalues.intSeq()AnIntegersequence generator.io()Provides access to IO generators.longs()Generator forLongvalues.longSeq()ALongsequence generator.math()Provides generators forjava.mathclasses.net()Provides generators forjava.netclasses.nio()Provides access to NIO generators.<T> OneOfCollectionSpec<T> oneOf(Collection<T> choices) Picks a random value from the given choices.<T> OneOfArraySpec<T> oneOf(T... choices) Picks a random value from the given choices.shorts()Generator forShortvalues.<T> ShuffleSpec<T> shuffle(Collection<T> collection) Creates a copy of the specified collection and shuffles its elements.<T> ShuffleSpec<T> shuffle(T... array) Creates a copy of the specified array and shuffles its elements.spatial()Provides access to spatial data type related generators.string()Generator forStringvalues.temporal()Provides access to temporal generators.text()Provides access to text generators.uuid()Generator forUUIDvalues.
-
Method Details
-
booleans
BooleanSpec booleans()Generator forBooleanvalues.- Specified by:
booleansin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
chars
CharacterSpec chars()Generator forCharactervalues.- Specified by:
charsin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
string
StringSpec string()Generator forStringvalues.- Specified by:
stringin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
bytes
ByteSpec bytes()Generator forBytevalues.- Specified by:
bytesin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
shorts
ShortSpec shorts()Generator forShortvalues.- Specified by:
shortsin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
ints
IntegerSpec ints()Generator forIntegervalues.- Specified by:
intsin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
intSeq
NumericSequenceSpec<Integer> intSeq()AnIntegersequence generator.- Specified by:
intSeqin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
longs
LongSpec longs()Generator forLongvalues.- Specified by:
longsin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
longSeq
NumericSequenceSpec<Long> longSeq()ALongsequence generator.- Specified by:
longSeqin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
floats
FloatSpec floats()Generator forFloatvalues.- Specified by:
floatsin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
doubles
DoubleSpec doubles()Generator forDoublevalues.- Specified by:
doublesin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
enumOf
Generator for enum values.- Specified by:
enumOfin interfaceCommonGeneratorSpecs- Type Parameters:
E- enum type- Parameters:
enumClass- type of enum to generate- Returns:
- API builder reference
- Since:
- 5.0.0
-
oneOf
Picks a random value from the given choices.- Specified by:
oneOfin interfaceCommonGeneratorSpecs- Type Parameters:
T- element type- Parameters:
choices- to choose from- Returns:
- API builder reference
- Since:
- 5.0.0
-
oneOf
Picks a random value from the given choices.- Specified by:
oneOfin interfaceCommonGeneratorSpecs- Type Parameters:
T- element type- Parameters:
choices- to choose from- Returns:
- API builder reference
- Since:
- 5.0.0
-
intervalStarting
A spec for generating intervals of various types, such as numeric and temporal values.Generating intervals requires three inputs:
- The start value of the first interval
- A function to calculate the end value based on the last start value
- A function to calculate the subsequent start value based on the last end value
To illustrate with an example, we will generate a list of vacations defined as:
record Vacation(LocalDate start, LocalDate end) {}The first vacation should start on
2000-01-01. Each vacation should last between1-3weeks. There should be12-15months between vacations.IntervalSupplier<LocalDate> intervals = Instancio.gen() .intervalStarting(LocalDate.of(2000, 1, 1)) .nextStart((end, random) -> end.plusMonths(random.intRange(12, 15))) .nextEnd((start, random) -> start.plusWeeks(random.intRange(1, 3))) .get();This method produces an
IntervalSuppliercontainingstartandendmethods, which return aSupplier. Each call tostart()andend()will produce new interval values.for (int i = 0; i < 4; i++) { System.out.println(interval.start().get() + " - " + interval.end().get()); } // Sample output: // 2000-01-01 - 2000-01-15 // 2001-02-15 - 2001-03-08 // 2002-03-08 - 2002-03-15 // 2003-06-15 - 2003-07-06The
start()andend()can be used to populateVacationobjects, for example:List<Vacation> vacations = Instancio.ofList(Vacation.class) .size(4) .supply(field(Vacation::start), intervals.start()) .supply(field(Vacation::end), intervals.end()) .create();- Type Parameters:
T- the type of value underlying the interval- Parameters:
startingValue- the starting value of the first interval- Returns:
- API builder reference
- Since:
- 5.0.0
- See Also:
-
shuffle
Creates a copy of the specified array and shuffles its elements.- Type Parameters:
T- the element type- Parameters:
array- containing the elements to shuffle- Returns:
- API builder reference
- Since:
- 5.0.0
-
shuffle
Creates a copy of the specified collection and shuffles its elements.- Type Parameters:
T- the element type- Parameters:
collection- containing the elements to shuffle- Returns:
- API builder reference
- Since:
- 5.0.0
-
io
IoSpecs io()Provides access to IO generators.- Specified by:
ioin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
math
MathSpecs math()Provides generators forjava.mathclasses.- Specified by:
mathin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
net
NetSpecs net()Provides generators forjava.netclasses.- Specified by:
netin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
nio
NioSpecs nio()Provides access to NIO generators.- Specified by:
nioin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
temporal
TemporalSpecs temporal()Provides access to temporal generators.- Specified by:
temporalin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
text
TextSpecs text()Provides access to text generators.- Specified by:
textin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
uuid
-
checksum
ChecksumSpecs checksum()Provides access to checksum generators.- Specified by:
checksumin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
id
IdSpecs id()Provides access to identifier generators.- Specified by:
idin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
hash
HashSpec hash()Generator for various types of hashes.- Specified by:
hashin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
finance
FinanceSpecs finance()Provides access to finance-related generators.- Specified by:
financein interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-
spatial
SpatialSpecs spatial()Provides access to spatial data type related generators.- Specified by:
spatialin interfaceCommonGeneratorSpecs- Returns:
- API builder reference
- Since:
- 5.0.0
-