Class GeneratorBase<Base extends GeneratorBase<Base,Context>,Context extends GeneratorContext<Context>>
- java.lang.Object
-
- net.morimekta.providence.testing.generator.GeneratorBase<Base,Context>
-
- Direct Known Subclasses:
SimpleGeneratorBase
public abstract class GeneratorBase<Base extends GeneratorBase<Base,Context>,Context extends GeneratorContext<Context>> extends java.lang.Object
Options and context container for managing a set of message generators and associated value generators. Note that all classes who extend the GeneratorBase must have a public copy constructor.
-
-
Constructor Summary
Constructors Constructor Description GeneratorBase()
Default generator context.GeneratorBase(io.codearte.jfairy.Fairy fairy, java.util.Random random)
GeneratorBase(io.codearte.jfairy.Fairy fairy, java.util.Random random, double defaultFillRate, int defaultMaxCollectionSize)
GeneratorBase(GeneratorBase<Base,Context> copyOf)
Copy constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Context
createContext()
Create the context instance used when generating messages.protected Base
deepCopy()
<E extends PEnumValue<E>>
Generator<Context,E>enumGeneratorFor(PEnumDescriptor<E> descriptor)
<T> Generator<Context,T>
generatorFor(PDescriptor type)
double
getDefaultFillRate()
int
getDefaultMaxCollectionSize()
io.codearte.jfairy.Fairy
getFairy()
java.util.Random
getRandom()
<M extends PMessage<M,F>,F extends PField>
MessageGenerator<Context,M,F>messageGeneratorFor(PMessageDescriptor<M,F> descriptor)
Get the default generator for type, or create one if it does not exists.Base
setDefaultFillRate(double defaultFillRate)
Base
setDefaultMaxCollectionSize(int defaultMaxCollectionSize)
Base
setFairy(io.codearte.jfairy.Fairy fairy)
Base
setRandom(java.util.Random random)
<E extends PEnumValue<E>>
BasewithEnumGenerator(PEnumDescriptor<E> descriptor, Generator<Context,E> generator)
Set the default enum generator for the enum type.<M extends PMessage<M,F>,F extends PField>
BasewithMessageGenerator(PMessageDescriptor<M,F> descriptor, java.util.function.Consumer<MessageGenerator<Context,M,F>> closure)
Get the default message generator for the given message type, and apply the closure context on that.<M extends PMessage<M,F>,F extends PField>
BasewithMessageGenerator(PMessageDescriptor<M,F> descriptor, MessageGenerator<Context,M,F> generator)
Set the default message generator for the message type.
-
-
-
Constructor Detail
-
GeneratorBase
public GeneratorBase()
Default generator context.
-
GeneratorBase
public GeneratorBase(io.codearte.jfairy.Fairy fairy, java.util.Random random)
- Parameters:
fairy
- Fairy instance.random
- Random instance.
-
GeneratorBase
public GeneratorBase(io.codearte.jfairy.Fairy fairy, java.util.Random random, double defaultFillRate, int defaultMaxCollectionSize)
- Parameters:
fairy
- Fairy instance.random
- Random instance.defaultFillRate
- The default fill rate.defaultMaxCollectionSize
- The max collection size.
-
GeneratorBase
public GeneratorBase(GeneratorBase<Base,Context> copyOf)
Copy constructor.- Parameters:
copyOf
- Instance to make copy of.
-
-
Method Detail
-
createContext
public abstract Context createContext()
Create the context instance used when generating messages.- Returns:
- The new context class.
-
generatorFor
@Nonnull public <T> Generator<Context,T> generatorFor(@Nonnull PDescriptor type)
-
enumGeneratorFor
@Nonnull public <E extends PEnumValue<E>> Generator<Context,E> enumGeneratorFor(PEnumDescriptor<E> descriptor)
-
messageGeneratorFor
@Nonnull public <M extends PMessage<M,F>,F extends PField> MessageGenerator<Context,M,F> messageGeneratorFor(PMessageDescriptor<M,F> descriptor)
Get the default generator for type, or create one if it does not exists. This generator can be modified and is kept around.- Type Parameters:
M
- The message type.F
- The message field type.- Parameters:
descriptor
- The message descriptor.- Returns:
- The message generator.
-
withEnumGenerator
@Nonnull public <E extends PEnumValue<E>> Base withEnumGenerator(PEnumDescriptor<E> descriptor, Generator<Context,E> generator)
Set the default enum generator for the enum type.- Type Parameters:
E
- The enum type.- Parameters:
descriptor
- The enum descriptor.generator
- The enum value generator.- Returns:
- The generator context.
-
withMessageGenerator
@Nonnull public <M extends PMessage<M,F>,F extends PField> Base withMessageGenerator(PMessageDescriptor<M,F> descriptor, MessageGenerator<Context,M,F> generator)
Set the default message generator for the message type.- Type Parameters:
M
- The message type.F
- The message field type.- Parameters:
descriptor
- The message descriptor.generator
- The message value generator.- Returns:
- The generator context.
-
withMessageGenerator
@Nonnull public <M extends PMessage<M,F>,F extends PField> Base withMessageGenerator(PMessageDescriptor<M,F> descriptor, java.util.function.Consumer<MessageGenerator<Context,M,F>> closure)
Get the default message generator for the given message type, and apply the closure context on that.- Type Parameters:
M
- The message type.F
- the message field type.- Parameters:
descriptor
- The message descriptor.closure
- The closure working on the generator.- Returns:
- The generator context.
-
getFairy
@Nonnull public io.codearte.jfairy.Fairy getFairy()
- Returns:
- The current fairy instance.
-
setFairy
@Nonnull public Base setFairy(io.codearte.jfairy.Fairy fairy)
- Parameters:
fairy
- The new fairy instance.- Returns:
- The generator context.
-
getRandom
@Nonnull public java.util.Random getRandom()
- Returns:
- The current random instance.
-
setRandom
@Nonnull public Base setRandom(java.util.Random random)
- Parameters:
random
- The new random instance.- Returns:
- The generator context.
-
getDefaultMaxCollectionSize
public int getDefaultMaxCollectionSize()
- Returns:
- The default max collection size.
-
setDefaultMaxCollectionSize
@Nonnull public Base setDefaultMaxCollectionSize(int defaultMaxCollectionSize)
- Parameters:
defaultMaxCollectionSize
- The new default max collection size.- Returns:
- The generator context.
-
getDefaultFillRate
public double getDefaultFillRate()
- Returns:
- The current default fill rate.
-
setDefaultFillRate
@Nonnull public Base setDefaultFillRate(double defaultFillRate)
- Parameters:
defaultFillRate
- The new default fill rate.- Returns:
- The generator context.
-
deepCopy
protected Base deepCopy()
-
-