Package org.instancio.generator
Interface ValueSpec<T>
- Type Parameters:
T
- type of value
- All Superinterfaces:
GeneratorSpec<T>
- All Known Subinterfaces:
BigDecimalSpec
,BigIntegerSpec
,BooleanSpec
,ByteSpec
,CharacterSpec
,CoordinateSpec
,CreditCardSpec
,CsvSpec
,DoubleSpec
,DurationSpec
,EanSpec
,EmailSpec
,EnumSpec<E>
,FilePathSpec<T>
,FileSpec
,FloatSpec
,HashSpec
,InstantSpec
,IntegerSpec
,Ip4Spec
,IsbnSpec
,LocalDateSpec
,LocalDateTimeSpec
,LocalTimeSpec
,LongSpec
,LoremIpsumSpec
,LuhnSpec
,Mod10Spec
,Mod11Spec
,NipSpec
,NumberSpec<T>
,NumericSequenceSpec<T>
,OffsetDateTimeSpec
,OffsetTimeSpec
,OneOfArraySpec<T>
,OneOfCollectionSpec<T>
,PathSpec
,PeriodSpec
,PeselSpec
,RegonSpec
,ShortSpec
,SinSpec
,SsnSpec
,StringSpec
,TemporalSpec<T>
,TextPatternSpec
,URISpec
,URLSpec
,UUIDSpec
,UUIDStringSpec
,YearMonthSpec
,YearSpec
,ZonedDateTimeSpec
A spec for generating simple value types, such as strings, numbers,
dates, and so on.
Provides support for generating values using the shorthand API:
String str = Gen.string().length(10).prefix("foo").get();
List<BigDecimal> list = Gen.math().bigDecimal().list(10);
where Gen
is the entry point for generating various types of values.
- Since:
- 2.6.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault T
get()
Generates a single value.list
(int size) Generates a list of values of specified size.default <R> R
Maps the generated value using the specified function.nullable()
Specifies that anull
value can be generatedstream()
Returns an infiniteStream
of values.toModel()
Returns the spec as aModel
.
-
Method Details
-
get
Generates a single value.- Returns:
- a random value
- Since:
- 2.6.0
-
list
Generates a list of values of specified size.- Parameters:
size
- of the list to generate- Returns:
- a list of random values
- Since:
- 2.6.0
-
stream
Returns an infiniteStream
of values.Since the stream is infinite,
Stream.limit(long)
must be called to avoid an infinite loop.- Returns:
- an infinite stream of values
- Since:
- 2.6.0
-
map
Maps the generated value using the specified function.- Type Parameters:
R
- result type- Parameters:
fn
- mapping function- Returns:
- the result of the mapping function
- Since:
- 2.6.0
-
toModel
Returns the spec as aModel
.Example:
Model<String> stringModel = Gen.string().length(10).digits().toModel(); String result = Instancio.create(stringModel);
- Returns:
- spec as a model
- Since:
- 2.6.0
-
nullable
Specifies that anull
value can be generated- Returns:
- spec builder reference
- Since:
- 2.11.0
-