Class ModernBeanStyle


  • public class ModernBeanStyle
    extends BeanStyle
    A 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.

    • 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.
    For example a property with name "zipCode" and type String in a bean class named Address would have following setter and getter: 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.

    • Constructor Detail

      • ModernBeanStyle

        protected ModernBeanStyle()
    • 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 class BeanStyle
        Parameters:
        method - the Method 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 class BeanStyle
        Parameters:
        method - the Method 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 via BeanStyle.isGetterMethod(Method).
        Specified by:
        convertGetterNameToFieldName in class BeanStyle
        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 via BeanStyle.isSetterMethod(Method).
        Specified by:
        convertSetterNameToFieldName in class BeanStyle
        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 class BeanStyle
        Parameters:
        beanType - the examined bean class
        getterMethod - a method of the beanType that is proven to be a potential getter
        setterMethod - a method of the beanType 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