Package org.instancio.generator
Interface ValueSpec<T>
- Type Parameters:
T- the type of generated values
- All Superinterfaces:
GeneratorSpec<T>,Supplier<T>
- All Known Subinterfaces:
BigDecimalSpec,BigIntegerSpec,BooleanSpec,ByteSpec,CharacterSpec,CnpjSpec,CoordinateSpec,CpfSpec,CreditCardSpec,CsvSpec,DoubleSpec,DurationSpec,EanSpec,EmailSpec,EnumSpec<E>,FeedSpec<T>,FilePathSpec<T>,FileSpec,FloatSpec,HashSpec,InnSpec,InstantSpec,IntegerSpec,IntervalSpec<T>,Ip4Spec,IsbnSpec,LocalDateSpec,LocalDateTimeSpec,LocalTimeSpec,LongSpec,LoremIpsumSpec,LuhnSpec,Mod10Spec,Mod11Spec,MonthDaySpec,NipSpec,NumberSpec<T>,NumericSequenceSpec<T>,OffsetDateTimeSpec,OffsetTimeSpec,OneOfArraySpec<T>,OneOfCollectionSpec<T>,PathSpec,PeriodSpec,PeselSpec,RegonSpec,ShortSpec,ShuffleSpec<T>,SinSpec,SsnSpec,StringSpec,TemporalSpec<T>,TextPatternSpec,TituloEleitoralSpec,URISpec,URLSpec,UUIDSpec,UUIDStringSpec,YearMonthSpec,YearSpec,ZonedDateTimeSpec
A spec for generating simple value types, such as strings, numbers,
dates, and so on. Note that this interface is not intended to be
implemented by users. Instead, instances of this class can be
created using the
Instancio.gen() method, which provides
a shorthand API for generating values:
Example:
ValueSpec<String> spec = Instancio.gen().string().digits().length(5).prefix("FOO-");
// Each call to get() will generate a random value, e.g.
String s1 = spec.get(); // Sample output: FOO-55025
String s2 = spec.get(); // Sample output: FOO-72941
In addition, value specs can generate lists of values:
List<BigDecimal> list = Instancio.gen().math().bigDecimal().scale(3).list(4);
// Sample output: [5233.423, 8510.780, 3306.888, 172.187]
- Since:
- 2.6.0
-
Method Summary
Modifier and TypeMethodDescriptionget()Generates a single value.list(int size) Generates a list of values of specified size.default <R> RMaps the generated value using the specified function.nullable()Specifies that anullvalue can be generatedstream()Returns an infiniteStreamof values.
-
Method Details
-
get
-
list
-
stream
Returns an infiniteStreamof values.Note that
Stream.limit(long)must be called to avoid an infinite loop.- Returns:
- an infinite stream of values
- Since:
- 2.6.0
-
map
-
nullable
-