Interface ValueSpecs

All Superinterfaces:
CommonGeneratorSpecs
All Known Subinterfaces:
InstancioGenApi

public interface ValueSpecs extends CommonGeneratorSpecs
Defines all built-in generators that are available via the Instancio.gen() method.
Since:
5.0.0
  • Method Details

    • booleans

      BooleanSpec booleans()
      Generator for Boolean values.
      Specified by:
      booleans in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • chars

      CharacterSpec chars()
      Generator for Character values.
      Specified by:
      chars in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • string

      StringSpec string()
      Generator for String values.
      Specified by:
      string in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • bytes

      ByteSpec bytes()
      Generator for Byte values.
      Specified by:
      bytes in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • shorts

      ShortSpec shorts()
      Generator for Short values.
      Specified by:
      shorts in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • ints

      IntegerSpec ints()
      Generator for Integer values.
      Specified by:
      ints in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • intSeq

      An Integer sequence generator.
      Specified by:
      intSeq in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • longs

      LongSpec longs()
      Generator for Long values.
      Specified by:
      longs in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • longSeq

      A Long sequence generator.
      Specified by:
      longSeq in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • floats

      FloatSpec floats()
      Generator for Float values.
      Specified by:
      floats in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • doubles

      DoubleSpec doubles()
      Generator for Double values.
      Specified by:
      doubles in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • enumOf

      <E extends Enum<E>> EnumSpec<E> enumOf(Class<E> enumClass)
      Generator for enum values.
      Specified by:
      enumOf in interface CommonGeneratorSpecs
      Type Parameters:
      E - enum type
      Parameters:
      enumClass - type of enum to generate
      Returns:
      API builder reference
      Since:
      5.0.0
    • oneOf

      <T> OneOfArraySpec<T> oneOf(T... choices)
      Picks a random value from the given choices.
      Specified by:
      oneOf in interface CommonGeneratorSpecs
      Type Parameters:
      T - element type
      Parameters:
      choices - to choose from
      Returns:
      API builder reference
      Since:
      5.0.0
    • oneOf

      <T> OneOfCollectionSpec<T> oneOf(Collection<T> choices)
      Picks a random value from the given choices.
      Specified by:
      oneOf in interface CommonGeneratorSpecs
      Type Parameters:
      T - element type
      Parameters:
      choices - to choose from
      Returns:
      API builder reference
      Since:
      5.0.0
    • intervalStarting

      @ExperimentalApi <T> IntervalSpec<T> intervalStarting(T startingValue)
      A spec for generating intervals of various types, such as numeric and temporal values.

      Generating intervals requires three inputs:

      • The start value of the first interval
      • A function to calculate the end value based on the last start value
      • A function to calculate the subsequent start value based on the last end value

      To illustrate with an example, we will generate a list of vacations defined as:

      
       record Vacation(LocalDate start, LocalDate end) {}
       

      The first vacation should start on 2000-01-01. Each vacation should last between 1-3 weeks. There should be 12-15 months between vacations.

      
       IntervalSupplier<LocalDate> intervals = Instancio.gen()
           .intervalStarting(LocalDate.of(2000, 1, 1))
           .nextStart((end, random) -> end.plusMonths(random.intRange(12, 15)))
           .nextEnd((start, random) -> start.plusWeeks(random.intRange(1, 3)))
           .get();
       

      This method produces an IntervalSupplier containing start and end methods, which return a Supplier. Each call to start() and end() will produce new interval values.

      
       for (int i = 0; i < 4; i++) {
           System.out.println(interval.start().get() + " - " + interval.end().get());
       }
       // Sample output:
       // 2000-01-01 - 2000-01-15
       // 2001-02-15 - 2001-03-08
       // 2002-03-08 - 2002-03-15
       // 2003-06-15 - 2003-07-06
       

      The start() and end() can be used to populate Vacation objects, for example:

      
       List<Vacation> vacations = Instancio.ofList(Vacation.class)
           .size(4)
           .supply(field(Vacation::start), intervals.start())
           .supply(field(Vacation::end), intervals.end())
           .create();
       
      Type Parameters:
      T - the type of value underlying the interval
      Parameters:
      startingValue - the starting value of the first interval
      Returns:
      API builder reference
      Since:
      5.0.0
      See Also:
    • shuffle

      @ExperimentalApi <T> ShuffleSpec<T> shuffle(T... array)
      Creates a copy of the specified array and shuffles its elements.
      Type Parameters:
      T - the element type
      Parameters:
      array - containing the elements to shuffle
      Returns:
      API builder reference
      Since:
      5.0.0
    • shuffle

      @ExperimentalApi <T> ShuffleSpec<T> shuffle(Collection<T> collection)
      Creates a copy of the specified collection and shuffles its elements.
      Type Parameters:
      T - the element type
      Parameters:
      collection - containing the elements to shuffle
      Returns:
      API builder reference
      Since:
      5.0.0
    • io

      IoSpecs io()
      Provides access to IO generators.
      Specified by:
      io in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • math

      MathSpecs math()
      Provides generators for java.math classes.
      Specified by:
      math in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • net

      NetSpecs net()
      Provides generators for java.net classes.
      Specified by:
      net in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • nio

      NioSpecs nio()
      Provides access to NIO generators.
      Specified by:
      nio in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • temporal

      TemporalSpecs temporal()
      Provides access to temporal generators.
      Specified by:
      temporal in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • text

      TextSpecs text()
      Provides access to text generators.
      Specified by:
      text in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • uuid

      UUIDSpec uuid()
      Generator for UUID values.
      Since:
      5.0.0
    • checksum

      ChecksumSpecs checksum()
      Provides access to checksum generators.
      Specified by:
      checksum in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • id

      IdSpecs id()
      Provides access to identifier generators.
      Specified by:
      id in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • hash

      HashSpec hash()
      Generator for various types of hashes.
      Specified by:
      hash in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • finance

      FinanceSpecs finance()
      Provides access to finance-related generators.
      Specified by:
      finance in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0
    • spatial

      SpatialSpecs spatial()
      Provides access to spatial data type related generators.
      Specified by:
      spatial in interface CommonGeneratorSpecs
      Returns:
      API builder reference
      Since:
      5.0.0