Interface JsGen<R extends JsValue>

  • All Superinterfaces:
    java.util.function.Function<java.util.Random,​java.util.function.Supplier<R>>
    All Known Implementing Classes:
    JsObjGen

    public interface JsGen<R extends JsValue>
    extends java.util.function.Function<java.util.Random,​java.util.function.Supplier<R>>
    • Method Summary

      All Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default <T extends JsValue>
      JsGen<T>
      flatMap​(java.util.function.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​(java.util.function.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 java.util.function.Supplier<R> sample()
      Return a supplier of realized values from this generator
      default java.util.function.Supplier<R> sample​(java.util.Random random)
      Return a supplier of realized values from this generator and the given seed
      default JsGen<R> suchThat​(java.util.function.Predicate<R> predicate)
      Creates a generator that generates values from this generator that satisfy the given predicate.
      default JsGen<R> suchThat​(java.util.function.Predicate<R> predicate, int tries)
      Creates a generator that generates values from this generator that satisfy the given predicate.
      • Methods inherited from interface java.util.function.Function

        andThen, apply, compose
    • 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​(java.util.function.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​(java.util.function.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 java.util.function.Supplier<R> sample()
        Return a supplier of realized values from this generator
        Returns:
        a supplier of values
      • sample

        default java.util.function.Supplier<R> sample​(java.util.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​(java.util.function.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​(java.util.function.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