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

public interface ValueSpec<T> extends GeneratorSpec<T>
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 Type
    Method
    Description
    default T
    get()
    Generates a single value.
    default List<T>
    list(int size)
    Generates a list of values of specified size.
    default <R> R
    map(Function<T,R> fn)
    Maps the generated value using the specified function.
    Specifies that a null value can be generated
    default Stream<T>
    Returns an infinite Stream of values.
    default Model<T>
    Returns the spec as a Model.
  • Method Details

    • get

      default T get()
      Generates a single value.
      Returns:
      a random value
      Since:
      2.6.0
    • list

      default List<T> list(int size)
      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

      default Stream<T> stream()
      Returns an infinite Stream 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

      default <R> R map(Function<T,R> fn)
      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

      default Model<T> toModel()
      Returns the spec as a Model.

      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

      ValueSpec<T> nullable()
      Specifies that a null value can be generated
      Returns:
      spec builder reference
      Since:
      2.11.0