Interface JsGen<R extends JsValue>

    • Method Summary

      All Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default <T extends JsValue>
      JsGen<T>
      flatMap​(Function<R,​JsGen<T>> f)
      Creates a new generator that passes the result of this generator into the given function `f`.
      default <T extends JsValue>
      JsGen<T>
      map​(Function<R,​T> f)
      Returns this generator but with the values transformed by the given map function
      default JsGen<?> nullable()
      returns a new generator that generates the same elements as this generator and NULL
      default JsGen<?> optional()
      returns a new generator that generates the same elements as this generator and NOTHING.
      default Supplier<R> sample()
      Return a supplier of realized values from this generator
      default Supplier<R> sample​(Random random)
      Return a supplier of realized values from this generator and the given seed
      default JsGen<R> suchThat​(Predicate<R> predicate)
      Creates a generator that generates values from this generator that satisfy the given predicate.
      default JsGen<R> suchThat​(Predicate<R> predicate, int tries)
      Creates a generator that generates values from this generator that satisfy the given predicate.
    • Method Detail

      • nullable

        default JsGen<?> nullable()
        returns a new generator that generates the same elements as this generator and NULL
        Returns:
        a new generator
      • flatMap

        default <T extends JsValueJsGen<T> flatMap​(Function<R,​JsGen<T>> f)
        Creates a new generator that passes the result of this generator into the given function `f`. `f` should return a new generator. This allows you to create new generators that depend on the value of other generators
        Type Parameters:
        T - the type of the generated values
        Parameters:
        f - the function
        Returns:
        a generator
      • optional

        default JsGen<?> optional()
        returns a new generator that generates the same elements as this generator and NOTHING. Inserting NOTHING in a json removes the element. Comes in handy to generate Json objects with different keys.
        Returns:
        a new generator
      • map

        default <T extends JsValueJsGen<T> map​(Function<R,​T> f)
        Returns this generator but with the values transformed by the given map function
        Type Parameters:
        T - type of the generated value
        Parameters:
        f - map function
        Returns:
        a new generator
      • sample

        default Supplier<R> sample()
        Return a supplier of realized values from this generator
        Returns:
        a supplier of values
      • sample

        default Supplier<R> sample​(Random random)
        Return a supplier of realized values from this generator and the given seed
        Parameters:
        random - the seed of the generator
        Returns:
        a supplier of values
      • suchThat

        default JsGen<R> suchThat​(Predicate<R> predicate)
        Creates a generator that generates values from this generator that satisfy the given predicate. Care is needed to ensure there is a high chance this generator will satisfy the predicate. By default, `suchThat` will try 100 times to generate a value that satisfies the predicate. If no value passes this predicate after this number of iterations, a runtime exception will be thrown.
        Parameters:
        predicate - the predicate satisfied by every generated value
        Returns:
        a generator
      • suchThat

        default JsGen<R> suchThat​(Predicate<R> predicate,
                                  int tries)
        Creates a generator that generates values from this generator that satisfy the given predicate. Care is needed to ensure there is a high chance this generator will satisfy the predicate. By default, `suchThat` will try specified number of times to generate a value that satisfies the predicate. If no value passes this predicate after this number of iterations, a runtime exception will be thrown.
        Parameters:
        predicate - the predicate satisfied by every generated value
        tries - the number of tries
        Returns:
        a generator