Package nl._42.beanie
Class BeanBuilder
java.lang.Object
nl._42.beanie.BeanBuilder
- All Implemented Interfaces:
ValueGenerator
Builds new bean instances.
- Since:
- Feb 14, 2014
- Author:
- Jeroen van Schagen
-
Constructor Summary
ConstructorDescriptionConstruct a simpleBeanBuilder
, please note that this builder by default does not yet support conversions and persistence.BeanBuilder
(BeanBuilder beanBuilder) Construct a newBeanBuilder
cloning the settings of an existing builder.BeanBuilder
(BeanConverter beanConverter, BeanSaver beanSaver) Construct a simpleBeanBuilder
.BeanBuilder
(BeanSaver beanSaver) Construct a simpleBeanBuilder
, please note that this builder by default does not yet support conversions. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deletes the bean.void
Deletes multiple beans.Generate a new value of the specified type.<T> T
generateSafely
(Class<T> beanClass) Generate a new bean, properly casted to the correct type.protected Object
generateValue
(Class<?> beanClass, PropertyDescriptor descriptor) final BeanGenerator
Retrieves the underlying bean generator.Retrieves the skipped properties.register
(Class<?> declaringClass, String propertyName, ValueGenerator generator) Register a value generation strategy for a specific property reference.register
(Class<?> valueType, ValueGenerator generator) Register a value generation strategy for a specific type.<T> BeanBuilder
Register a value generation strategy for a specific type.register
(Supportable predicate, ValueGenerator generator) Register a value generation strategy for a specific type.registerIf
(Predicate<AccessibleObject> predicate, ValueGenerator generator) Register a value generation strategy for a specific type.registerValue
(Class<?> valueType, Object value) Register a constant value for a specific type.registerValue
(Class<?> declaringClass, String propertyName, Object value) Register a constant value for a specific property reference.<T> T
save
(T bean) Saves the bean.void
setBeanConverter
(BeanConverter beanConverter) void
setBeanSaver
(BeanSaver beanSaver) Skip a property from being generated.<T> EditableBeanBuildCommand<T>
Start building a new bean.<T> EditableBeanBuildCommand<T>
start
(T bean) Start building a new bean.<I extends BeanBuildCommand<?>>
IStart building a new bean, using a custom builder interface.<I extends BeanBuildCommand<T>,
T>
IStart building a new bean, using a custom builder interface.
-
Constructor Details
-
BeanBuilder
public BeanBuilder()Construct a simpleBeanBuilder
, please note that this builder by default does not yet support conversions and persistence. -
BeanBuilder
Construct a simpleBeanBuilder
, please note that this builder by default does not yet support conversions.- Parameters:
beanSaver
- used to save constructed beans- See Also:
-
BeanBuilder
Construct a simpleBeanBuilder
.- Parameters:
beanConverter
- used to convert beans between typesbeanSaver
- used to save constructed beans
-
BeanBuilder
Construct a newBeanBuilder
cloning the settings of an existing builder.- Parameters:
beanBuilder
- the builder instance to clone from
-
-
Method Details
-
start
Start building a new bean.- Type Parameters:
T
- the bean type- Parameters:
beanClass
- the type of bean to start building- Returns:
- the bean build command
-
start
Start building a new bean.- Type Parameters:
T
- the bean type- Parameters:
bean
- the initial bean- Returns:
- the bean build command
-
startAs
Start building a new bean, using a custom builder interface.- Type Parameters:
I
- the interface type- Parameters:
interfaceType
- the build command interface- Returns:
- the builder instance, capable of building beans
-
startAs
Start building a new bean, using a custom builder interface.- Type Parameters:
I
- the interface typeT
- the bean type- Parameters:
interfaceType
- the build command interfacebean
- the template bean- Returns:
- the builder instance, capable of building beans
-
generate
Generate a new value of the specified type.- Specified by:
generate
in interfaceValueGenerator
- Parameters:
beanClass
- the type of value- Returns:
- the generation value
-
generateSafely
Generate a new bean, properly casted to the correct type.- Type Parameters:
T
- the bean type- Parameters:
beanClass
- the bean class- Returns:
- the generated bean
-
generateValue
-
skip
Skip a property from being generated.- Parameters:
declaringClass
- the bean that declares this propertypropertyName
- the property name- Returns:
- this instance
-
register
Register a value generation strategy for a specific property reference.- Parameters:
declaringClass
- the bean class that declares our propertypropertyName
- the name of the propertygenerator
- the generation strategy- Returns:
- this instance
-
registerValue
Register a constant value for a specific property reference.- Parameters:
declaringClass
- the bean class that declares our propertypropertyName
- the name of the propertyvalue
- the value to return- Returns:
- this instance
-
register
Register a value generation strategy for a specific type.- Parameters:
valueType
- the type of valuegenerator
- the generation strategy- Returns:
- this instance
-
register
Register a value generation strategy for a specific type.- Parameters:
valueType
- the type of valuegenerator
- the generation strategy- Returns:
- this instance
-
register
Register a value generation strategy for a specific type.- Parameters:
predicate
- the support predicategenerator
- the generation strategy- Returns:
- this instance
-
registerIf
Register a value generation strategy for a specific type.- Parameters:
predicate
- the support predicategenerator
- the generation strategy- Returns:
- this instance
-
registerValue
Register a constant value for a specific type.- Parameters:
valueType
- the type of valuevalue
- the value to return- Returns:
- this instance
-
save
public <T> T save(T bean) Saves the bean.- Type Parameters:
T
- the bean type- Parameters:
bean
- the bean to save- Returns:
- the saved bean
-
delete
Deletes the bean.- Parameters:
bean
- the bean to delete
-
deleteAll
Deletes multiple beans.- Parameters:
beans
- the beans to delete
-
getBeanGenerator
Retrieves the underlying bean generator.- Returns:
- the bean generator
-
getSkippedProperties
Retrieves the skipped properties.- Returns:
- the skipped properties
-
setBeanSaver
- Parameters:
beanSaver
- the saver to set
-
setBeanConverter
- Parameters:
beanConverter
- the converter to set
-