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, WordSpec, YearMonthSpec, YearSpec, ZonedDateTimeSpec

public interface ValueSpec<T> extends GeneratorSpec<T>, Supplier<T>
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 Type
    Method
    Description
    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.
  • Method Details

    • get

      T get()
      Generates a single value.
      Specified by:
      get in interface Supplier<T>
      Returns:
      generated 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.

      Note that 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
    • nullable

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