Interface MetaProperty<P>

  • Type Parameters:
    P - the type of the property content
    All Known Implementing Classes:
    BasicMetaProperty, DirectMetaProperty, StandaloneMetaProperty

    public interface MetaProperty<P>
    A meta-property, defining those aspects of a property which are not specific to a particular bean, such as the property type and name.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default <A extends java.lang.annotation.Annotation>
      A
      annotation​(java.lang.Class<A> annotationClass)
      Gets an annotation from the property.
      java.util.List<java.lang.annotation.Annotation> annotations()
      Gets the annotations of the property.
      default Property<P> createProperty​(Bean bean)
      Creates a property that binds this meta-property to a specific bean.
      java.lang.Class<?> declaringType()
      Get the type that declares the property, represented as a Class.
      boolean equals​(java.lang.Object obj)
      Checks if this meta-property equals another.
      P get​(Bean bean)
      Gets the value of the property for the specified bean.
      default java.lang.String getString​(Bean bean)
      Gets the value of the property for the specified bean converted to a string.
      default java.lang.String getString​(Bean bean, org.joda.convert.StringConvert stringConvert)
      Gets the value of the property for the specified bean converted to a string.
      int hashCode()
      Returns a suitable hash code.
      MetaBean metaBean()
      Gets the meta-bean which owns this meta-property.
      java.lang.String name()
      Gets the property name.
      java.lang.reflect.Type propertyGenericType()
      Gets the generic types of the property.
      java.lang.Class<P> propertyType()
      Get the type of the property represented as a Class.
      default P put​(Bean bean, java.lang.Object value)
      Sets the value of the property on the associated bean and returns the previous value.
      void set​(Bean bean, java.lang.Object value)
      Sets the value of the property on the specified bean.
      default void setString​(Bean bean, java.lang.String value)
      Sets the value of the property on the specified bean from a string by conversion.
      default void setString​(Bean bean, java.lang.String value, org.joda.convert.StringConvert stringConvert)
      Sets the value of the property on the specified bean from a string by conversion.
      PropertyStyle style()
      Gets the style of the property, such as read-only, read-write or write-only.
    • Method Detail

      • createProperty

        default Property<P> createProperty​(Bean bean)
        Creates a property that binds this meta-property to a specific bean.

        This method returns a Property instance that connects this meta-property to the specified bean. The result can be queried and passed around without further reference to the bean.

        Parameters:
        bean - the bean to create the property for, not null
        Returns:
        the property, not null
      • metaBean

        MetaBean metaBean()
        Gets the meta-bean which owns this meta-property.

        Each meta-property is fully owned by a single bean.

        Returns:
        the meta-bean, not null
      • name

        java.lang.String name()
        Gets the property name.

        The JavaBean style methods getFoo() and setFoo() will lead to a property name of 'foo' and so on.

        Returns:
        the name of the property, not empty
      • declaringType

        java.lang.Class<?> declaringType()
        Get the type that declares the property, represented as a Class.

        This is the type of the bean where the property is declared.

        Returns:
        the type declaring the property, not null
      • propertyType

        java.lang.Class<P> propertyType()
        Get the type of the property represented as a Class.

        This is the type of the property. For example, the surname of a person would typically be a String.

        Returns:
        the type of the property, not null
      • propertyGenericType

        java.lang.reflect.Type propertyGenericType()
        Gets the generic types of the property.

        This provides access to the generic type declared in the source code.

        Returns:
        the full generic type of the property, unmodifiable, not null
      • style

        PropertyStyle style()
        Gets the style of the property, such as read-only, read-write or write-only.

        Rather than testing against specific values, it is strongly recommended to call the helper methods on the returned style.

        Returns:
        the property style, not null
      • annotations

        java.util.List<java.lang.annotation.Annotation> annotations()
        Gets the annotations of the property.

        The annotations are queried from the property. This is typically accomplished by querying the annotations of the underlying instance variable however any strategy is permitted.

        Returns:
        the annotations, unmodifiable, not null
      • annotation

        default <A extends java.lang.annotation.Annotation> A annotation​(java.lang.Class<A> annotationClass)
        Gets an annotation from the property.

        The annotations are queried from the property. This is typically accomplished by querying the annotations of the underlying instance variable however any strategy is permitted..

        Type Parameters:
        A - the annotation type
        Parameters:
        annotationClass - the annotation class to find, not null
        Returns:
        the annotation, not null
        Throws:
        java.util.NoSuchElementException - if the annotation is not specified
      • get

        P get​(Bean bean)
        Gets the value of the property for the specified bean.

        For a standard JavaBean, this is equivalent to calling getFoo() on the bean. Alternate implementations may perform any logic to obtain the value.

        Parameters:
        bean - the bean to query, not null
        Returns:
        the value of the property on the specified bean, may be null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.UnsupportedOperationException - if the property is write-only
      • set

        void set​(Bean bean,
                 java.lang.Object value)
        Sets the value of the property on the specified bean.

        The value must be of the correct type for the property. For a standard JavaBean, this is equivalent to calling setFoo() on the bean. Alternate implementations may perform any logic to change the value.

        Parameters:
        bean - the bean to update, not null
        value - the value to set into the property on the specified bean, may be null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.ClassCastException - if the value is of an invalid type for the property
        java.lang.UnsupportedOperationException - if the property is read-only
        java.lang.RuntimeException - if the value is rejected by the property (use appropriate subclasses)
      • put

        default P put​(Bean bean,
                      java.lang.Object value)
        Sets the value of the property on the associated bean and returns the previous value.

        The value must be of the correct type for the property. This is a combination of the get and set methods that matches the definition of put in a Map.

        Parameters:
        bean - the bean to update, not null
        value - the value to set into the property on the specified bean, may be null
        Returns:
        the old value of the property, may be null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.ClassCastException - if the value is of an invalid type for the property
        java.lang.UnsupportedOperationException - if the property is read-only
        java.lang.RuntimeException - if the value is rejected by the property (use appropriate subclasses)
      • getString

        default java.lang.String getString​(Bean bean)
        Gets the value of the property for the specified bean converted to a string.

        This converts the result of get(Bean) to a standard format string. Conversion uses Joda-Convert. Not all object types can be converted to a string, see Joda-Convert.

        For a standard JavaBean, this is equivalent to calling getFoo() on the bean. Alternate implementations may perform any logic to obtain the value.

        Parameters:
        bean - the bean to query, not null
        Returns:
        the value of the property on the specified bean, may be null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.UnsupportedOperationException - if the property is write-only
        java.lang.RuntimeException - if the value cannot be converted to a string (use appropriate subclasses)
      • getString

        default java.lang.String getString​(Bean bean,
                                           org.joda.convert.StringConvert stringConvert)
        Gets the value of the property for the specified bean converted to a string.

        This converts the result of get(Bean) to a standard format string using the supplied converter. Not all object types can be converted to a string, see Joda-Convert.

        For a standard JavaBean, this is equivalent to calling getFoo() on the bean. Alternate implementations may perform any logic to obtain the value.

        Parameters:
        bean - the bean to query, not null
        stringConvert - the converter to use, not null
        Returns:
        the value of the property on the specified bean, may be null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.UnsupportedOperationException - if the property is write-only
        java.lang.RuntimeException - if the value cannot be converted to a string (use appropriate subclasses)
      • setString

        default void setString​(Bean bean,
                               java.lang.String value)
        Sets the value of the property on the specified bean from a string by conversion.

        This converts the string to the correct type for the property and then sets it using set(Bean, Object). Conversion uses Joda-Convert.

        Parameters:
        bean - the bean to update, not null
        value - the value to set into the property on the specified bean, may be null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.ClassCastException - if the value is of an invalid type for the property
        java.lang.UnsupportedOperationException - if the property is read-only
        java.lang.RuntimeException - if the value is rejected by the property (use appropriate subclasses)
      • setString

        default void setString​(Bean bean,
                               java.lang.String value,
                               org.joda.convert.StringConvert stringConvert)
        Sets the value of the property on the specified bean from a string by conversion.

        This converts the string to the correct type for the property using the supplied converter and then sets it using set(Bean, Object).

        Parameters:
        bean - the bean to update, not null
        value - the value to set into the property on the specified bean, may be null
        stringConvert - the converter, not null
        Throws:
        java.lang.ClassCastException - if the bean is of an incorrect type
        java.lang.ClassCastException - if the value is of an invalid type for the property
        java.lang.UnsupportedOperationException - if the property is read-only
        java.lang.RuntimeException - if the value is rejected by the property (use appropriate subclasses)
      • equals

        boolean equals​(java.lang.Object obj)
        Checks if this meta-property equals another.

        This compares the property name and declaring type. It does not compare the property or bean types.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other meta-property, null returns false
        Returns:
        true if equal
      • hashCode

        int hashCode()
        Returns a suitable hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code