Package org.coliper.ibean.beanstyle
Class ModernBeanStyle
- java.lang.Object
-
- org.coliper.ibean.BeanStyle
-
- org.coliper.ibean.beanstyle.ModernBeanStyle
-
public class ModernBeanStyle extends BeanStyle
ABeanStyle
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.
- The getter has no arguments and returns the property type.
- The setter has one argument with property type and returns the bean class. The returned object is always the bean itself. By this you can chain setter calls easily.
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 isnull
then an empty Optional instance will be returned.
-
-
Field Summary
Fields Modifier and Type Field Description static ModernBeanStyle
INSTANCE
-
Fields inherited from class org.coliper.ibean.BeanStyle
CLASSIC, CLASSIC_WITH_OPTIONAL, MODERN
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ModernBeanStyle()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.coliper.ibean.BeanStyle
assertForBeanType, equals, hashCode, isNoParameterInMethod, isOneParameterInMethod
-
-
-
-
Field Detail
-
INSTANCE
public static final ModernBeanStyle INSTANCE
-
-
Method Detail
-
isGetterMethod
public boolean isGetterMethod(Method method)
Description copied from class:BeanStyle
Determines if a given method is a potential getter method for this bean type. Typically it checks if the method confirms to the required signature and naming convention of the style. This method should not do any checks about the type the method belongs to.See
ClassicBeanStyle.isGetterMethod(Method)
for a concrete example.- Specified by:
isGetterMethod
in classBeanStyle
- Parameters:
method
- theMethod
to test- Returns:
true
if the method matches the requirements for a getter
-
isSetterMethod
public boolean isSetterMethod(Method method)
Description copied from class:BeanStyle
Determines if a given method is a potential setter method for this bean type. Typically it checks if the method confirms to the required signature and naming convention of the style. This method should not do any checks about the type the method belongs to.See
ClassicBeanStyle.isSetterMethod(Method)
for a concrete example.- Specified by:
isSetterMethod
in classBeanStyle
- Parameters:
method
- theMethod
to test- Returns:
true
if the method matches the requirements for a setter
-
convertGetterNameToFieldName
public String convertGetterNameToFieldName(String getterName)
Description copied from class:BeanStyle
Derives the name of a bean field from the name of its corresponding getter method. This method can assume that the given getter name has been checked for compliance viaBeanStyle.isGetterMethod(Method)
.- Specified by:
convertGetterNameToFieldName
in classBeanStyle
- Parameters:
getterName
- the name of a method that has been identified as a potential getter- Returns:
- the name of the bean field; names are case sensitive
-
convertSetterNameToFieldName
public String convertSetterNameToFieldName(String setterName)
Description copied from class:BeanStyle
Derives the name of a bean field from the name of its corresponding setter method. This method can assume that the given setter name has been checked for compliance viaBeanStyle.isSetterMethod(Method)
.- Specified by:
convertSetterNameToFieldName
in classBeanStyle
- Parameters:
setterName
- the name of a method that has been identified as a potential setter- Returns:
- the name of the bean field; names are case sensitive
-
determineFieldTypeFromGetterAndSetter
public Class<?> determineFieldTypeFromGetterAndSetter(Class<?> beanType, Method getterMethod, Method setterMethod) throws InvalidIBeanTypeException
Description copied from class:BeanStyle
Determines the type of a bean field from given corresponding getter and setter method. Implementations of this method can assume that both given methods have been checked for getter and setter compliance and that both methods match in terms of method names. Implementations need to determine the type of the field and need to check if both getter and setter match to the type. That means that for example not only the given setter should be looked at to find out the field type.- Specified by:
determineFieldTypeFromGetterAndSetter
in classBeanStyle
- Parameters:
beanType
- the examined bean classgetterMethod
- a method of thebeanType
that is proven to be a potential gettersetterMethod
- a method of thebeanType
that is proven to be a potential setter- Returns:
- the type of the bean field
- Throws:
InvalidIBeanTypeException
- if either the type cannot be determined for any reason or if the concluded types of setter and getter do not match
-
-