public class ModernBeanStyle extends BeanStyle
BeanStyle implementation that has getters and
setters named equal to the property and that return "this" from setters to
allow setter chaining.
In many modern libraries you see a different way of defining setter and getter methods taken from other programming languages like C++. This bean style reflects the most common one.
For each property for a bean you basically have a getter and a setter that are equally named to the property.
Adress zipCode(String c);
String zipCode();
This bean style also supports Optional as return type for every
getter. For example:
public interface BeanInterface {
BeanInterface setValue(String val);
Optional<String> getValue();
}
If the field value is null then an empty Optional
instance will be returned.
| Modifier and Type | Field and Description |
|---|---|
static ModernBeanStyle |
INSTANCE |
CLASSIC, CLASSIC_WITH_OPTIONAL, MODERN| Modifier | Constructor and Description |
|---|---|
protected |
ModernBeanStyle() |
| Modifier and Type | Method and Description |
|---|---|
String |
convertGetterNameToFieldName(String getterName)
Derives the name of a bean field from the name of its corresponding
getter method.
|
String |
convertSetterNameToFieldName(String setterName)
Derives the name of a bean field from the name of its corresponding
setter method.
|
Class<?> |
determineFieldTypeFromGetterAndSetter(Class<?> beanType,
Method getterMethod,
Method setterMethod)
Determines the type of a bean field from given corresponding getter and
setter method.
|
boolean |
isGetterMethod(Method method)
Determines if a given method is a potential getter method for this bean
type.
|
boolean |
isSetterMethod(Method method)
Determines if a given method is a potential setter method for this bean
type.
|
assertForBeanType, equals, hashCode, isNoParameterInMethod, isOneParameterInMethodpublic static final ModernBeanStyle INSTANCE
public boolean isGetterMethod(Method method)
BeanStyle
See ClassicBeanStyle.isGetterMethod(Method) for a concrete
example.
isGetterMethod in class BeanStylemethod - the Method to testtrue if the method matches the requirements for a
getterpublic boolean isSetterMethod(Method method)
BeanStyle
See ClassicBeanStyle.isSetterMethod(Method) for a concrete
example.
isSetterMethod in class BeanStylemethod - the Method to testtrue if the method matches the requirements for a
setterpublic String convertGetterNameToFieldName(String getterName)
BeanStyleBeanStyle.isGetterMethod(Method).convertGetterNameToFieldName in class BeanStylegetterName - the name of a method that has been identified as a potential
getterpublic String convertSetterNameToFieldName(String setterName)
BeanStyleBeanStyle.isSetterMethod(Method).convertSetterNameToFieldName in class BeanStylesetterName - the name of a method that has been identified as a potential
setterpublic Class<?> determineFieldTypeFromGetterAndSetter(Class<?> beanType, Method getterMethod, Method setterMethod) throws InvalidIBeanTypeException
BeanStyledetermineFieldTypeFromGetterAndSetter in class BeanStylebeanType - the examined bean classgetterMethod - a method of the beanType that is proven to be a
potential gettersetterMethod - a method of the beanType that is proven to be a
potential setterInvalidIBeanTypeException - if either the type cannot be determined for any reason or if
the concluded types of setter and getter do not match