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.ObjectOptions 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 ContextcreateContext()Create the context instance used when generating messages.protected BasedeepCopy()<E extends net.morimekta.providence.PEnumValue<E>>
Generator<Context,E>enumGeneratorFor(net.morimekta.providence.descriptor.PEnumDescriptor<E> descriptor)<T> Generator<Context,T>generatorFor(net.morimekta.providence.descriptor.PDescriptor type)doublegetDefaultFillRate()intgetDefaultMaxCollectionSize()io.codearte.jfairy.FairygetFairy()java.util.RandomgetRandom()<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
MessageGenerator<Context,M,F>messageGeneratorFor(net.morimekta.providence.descriptor.PMessageDescriptor<M,F> descriptor)Get the default generator for type, or create one if it does not exists.BasesetDefaultFillRate(double defaultFillRate)BasesetDefaultMaxCollectionSize(int defaultMaxCollectionSize)BasesetFairy(io.codearte.jfairy.Fairy fairy)BasesetRandom(java.util.Random random)<E extends net.morimekta.providence.PEnumValue<E>>
BasewithEnumGenerator(net.morimekta.providence.descriptor.PEnumDescriptor<E> descriptor, Generator<Context,E> generator)Set the default enum generator for the enum type.<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
BasewithMessageGenerator(net.morimekta.providence.descriptor.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 net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
BasewithMessageGenerator(net.morimekta.providence.descriptor.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 net.morimekta.providence.descriptor.PDescriptor type)
-
enumGeneratorFor
@Nonnull public <E extends net.morimekta.providence.PEnumValue<E>> Generator<Context,E> enumGeneratorFor(net.morimekta.providence.descriptor.PEnumDescriptor<E> descriptor)
-
messageGeneratorFor
@Nonnull public <M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField> MessageGenerator<Context,M,F> messageGeneratorFor(net.morimekta.providence.descriptor.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 net.morimekta.providence.PEnumValue<E>> Base withEnumGenerator(net.morimekta.providence.descriptor.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 net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField> Base withMessageGenerator(net.morimekta.providence.descriptor.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 net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField> Base withMessageGenerator(net.morimekta.providence.descriptor.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()
-
-