Package org.instancio.generator.specs
Interface AsGeneratorSpec<T>
- Type Parameters:
T- generated type
- All Superinterfaces:
GeneratorSpec<T>
- All Known Subinterfaces:
BigDecimalAsGeneratorSpec,BooleanAsGeneratorSpec,CharacterAsGeneratorSpec,EmailAsGeneratorSpec,EnumAsGeneratorSpec<E>,HashAsGeneratorSpec,MonthDayGeneratorSpec,NumberAsGeneratorSpec<T>,PathAsGeneratorSpec<T>,TemporalAaStringGeneratorSpec<T>,URIAsGeneratorSpec,URLAsGeneratorSpec
- All Known Implementing Classes:
AbstractRandomComparableNumberGeneratorSpec,AbstractRandomNumberGeneratorSpec,AtomicIntegerGenerator,AtomicLongGenerator,BigDecimalGenerator,BigIntegerGenerator,BooleanGenerator,ByteGenerator,CharacterGenerator,DoubleGenerator,EmailGenerator,EnumGenerator,FileGenerator,FloatGenerator,HashGenerator,InstantGenerator,IntegerGenerator,LocalDateGenerator,LocalDateTimeGenerator,LocalTimeGenerator,LongGenerator,MonthDayGenerator,OffsetDateTimeGenerator,OffsetTimeGenerator,PathGenerator,ShortGenerator,URIGenerator,URLGenerator,YearGenerator,YearMonthGenerator,ZonedDateTimeGenerator
Allows mapping the result of a generator to another type.
- Since:
- 2.11.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault <R> GeneratorSpec<R>Converts the generated value to another type using the specified mapping function.default GeneratorSpec<String>asString()Converts the generated value to aString.
-
Method Details
-
asString
Converts the generated value to aString.- Returns:
- generator spec with the result mapped to a string
using
Object.toString() - Since:
- 2.11.0
-
as
Converts the generated value to another type using the specified mapping function.Example:
record Log(String msg, long timestamp) {} LogEntry result = Instancio.of(LogEntry.class) .generate(field(Log::timestamp), gen -> gen.temporal().instant().past().as(Instant::toEpochMilli)) .create();- Type Parameters:
R- resulting type after applying the function- Parameters:
mappingFunction- for mapping generated value to another type- Returns:
- generator spec with mapped result
- Since:
- 2.11.0
-