T
- the type to be createdpublic class RandomFactory<T> extends Object implements RandomField
Modifier and Type | Class and Description |
---|---|
static interface |
RandomFactory.Supplier<U>
Represents a supplier of results.
|
RND
Constructor and Description |
---|
RandomFactory(RandomFactory.Supplier<T> pojoSupplier)
A constructor that takes one
RandomFactory.Supplier . |
RandomFactory(RandomFactory.Supplier<T> pojoSupplier,
Map<String,RandomField> fieldMapping)
A constructor that takes one class and the mapping of properties to the factories
filling them.
|
Modifier and Type | Method and Description |
---|---|
void |
addRandomField(String property,
RandomField randomField)
Adds a
RandomField to fill some property. |
List<T> |
create(int count)
Creates some instances of the POJO this factory is for.
|
T |
createSingle()
Creates a single instance of the class this factory is for.
|
RandomField |
findRandomField(String property)
Returns the
RandomField used to fill the property. |
static <U> RandomFactory<U> |
forClass(Class<U> pojoClass)
Creates a
RandomFactory with just one class and then tries to guess which
fields to fill. |
RandomField |
getRandomField(String property)
Returns the
RandomField used to fill the property. |
T |
nextValue()
Returns a random value.
|
void |
removeRandomField(String property)
Removes a
RandomField . |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
init
public RandomFactory(RandomFactory.Supplier<T> pojoSupplier)
RandomFactory.Supplier
. The mapping of properties to the
factories filling them is guessed.pojoSupplier
- the supplier for the POJOpublic RandomFactory(RandomFactory.Supplier<T> pojoSupplier, Map<String,RandomField> fieldMapping)
pojoSupplier
- the supplier for the POJOfieldMapping
- the initial mapping for the fieldspublic static <U> RandomFactory<U> forClass(Class<U> pojoClass)
RandomFactory
with just one class and then tries to guess which
fields to fill. Might not be the best option for some cases.U
- the class that should be generatedpojoClass
- the class of the POJO to be created; the class must have a default
constructor and be publicRandomFactory
with guessed mappingpublic T nextValue()
RandomField
nextValue
in interface RandomField
public T createSingle() throws RandomException
RandomException
- - if something went wrongpublic List<T> create(int count)
count
- number of instances to be createdRandomException
- - if something went wrongpublic RandomField getRandomField(String property)
RandomField
used to fill the property.property
- the propertyRandomException
- if no RandomField
was foundpublic RandomField findRandomField(String property)
RandomField
used to fill the property.property
- the propertypublic void addRandomField(String property, RandomField randomField)
RandomField
to fill some property.property
- the propertyrandomField
- the random field to fill this property; can be nullpublic void removeRandomField(String property)
RandomField
.property
- the propertyCopyright © 2020. All rights reserved.