Class GeneratorContext<Context extends GeneratorContext<Context>>

  • Type Parameters:
    Context - The context implementation type.
    Direct Known Subclasses:
    GeneratorContext.Simple, SimpleGeneratorWatcher.Context

    public class GeneratorContext<Context extends GeneratorContext<Context>>
    extends java.lang.Object
    This is the core generator context, which essentially brings all things to be generated together. It has full knowledge about all the generators, where state is more or less copied from parent generators. And the current generating context.
    • Constructor Detail

      • GeneratorContext

        public GeneratorContext()
        Create a fresh generator.
      • GeneratorContext

        protected GeneratorContext​(GeneratorContext<Context> parent)
        Create a generator instance as copy of another instance. The new generator can then be updated without interfering with the parent.
        Parameters:
        parent - The parent generator instance.
    • Method Detail

      • deepCopy

        public Context deepCopy()
      • setFillRate

        public Context setFillRate​(double v)
      • setMinCollectionSize

        public Context setMinCollectionSize​(int v)
      • setMaxCollectionSize

        public Context setMaxCollectionSize​(int v)
      • getRandom

        public java.util.Random getRandom()
      • setRandom

        public Context setRandom​(java.util.Random random)
      • getProperty

        public <V> V getProperty​(java.lang.String name)
      • createPropertyIfAbsent

        public <V> V createPropertyIfAbsent​(java.lang.String name,
                                            java.util.function.Supplier<V> propertySupplier)
      • setProperty

        public <V> Context setProperty​(java.lang.String name,
                                       V value)
      • withGenerator

        @Nonnull
        public <V> Context withGenerator​(PDescriptor descriptor,
                                         Generator<Context,​V> generator)
        Set a specific value generator based on type for default value generator.
        Type Parameters:
        V - The value type.
        Parameters:
        descriptor - The type to be generated.
        generator - The value generator.
        Returns:
        The generator instance.
      • withMessageGenerator

        @Nonnull
        public <M extends PMessage<M>,​MOB extends PMessageOrBuilder<M>> GeneratorContext<Context> withMessageGenerator​(@Nonnull
                                                                                                                             PMessageDescriptor<M> descriptor,
                                                                                                                             @Nonnull
                                                                                                                             java.util.function.Consumer<MessageGenerator<Context,​M,​MOB>> closure)
        Update the generator for the given message type.
        Type Parameters:
        M - The message type to have updated generator.
        MOB - The message or builder interface.
        Parameters:
        descriptor - The message descriptor.
        closure - Closure updating the generator.
        Returns:
        The generator instance.
      • nextMessage

        public <M extends PMessage<M>> M nextMessage​(@Nonnull
                                                     PMessageDescriptor<M> descriptor)
        Create a message based on the current generator.
        Type Parameters:
        M - The message type.
        Parameters:
        descriptor - The message descriptor.
        Returns:
        The generated message.
      • nextMessage

        public <M extends PMessage<M>,​MOB extends PMessageOrBuilder<M>> M nextMessage​(@Nonnull
                                                                                            PMessageDescriptor<M> descriptor,
                                                                                            @Nonnull
                                                                                            java.util.function.Consumer<MessageGenerator<Context,​M,​MOB>> closure)
        Create a message based on a modified generator.
        Type Parameters:
        M - The message type.
        MOB - The message or builder interface.
        Parameters:
        descriptor - The message descriptor.
        closure - Closure updating the generator for this case only.
        Returns:
        The generated message.
      • nextCollectionSize

        public int nextCollectionSize()
      • nextFieldIsPresent

        public boolean nextFieldIsPresent()
      • getGeneratedMessages

        public java.util.List<PMessage> getGeneratedMessages()
      • clearGeneratedMessages

        public void clearGeneratedMessages()