Interface BeanProperty<B,​T>

    • Method Detail

      • get

        @Nullable
        T get​(@NonNull
              B bean)
        Read the bean value.
        Parameters:
        bean - The bean to read from
        Returns:
        The value
        Throws:
        java.lang.IllegalArgumentException - If the bean instance if not of the correct type
      • get

        @NonNull
        default <T2> java.util.Optional<T2> get​(@NonNull
                                                B bean,
                                                @NonNull
                                                java.lang.Class<T2> type)
        Read the value and try to convert it to the given type.
        Type Parameters:
        T2 - The generic type
        Parameters:
        bean - The bean
        type - The type
        Returns:
        The value if conversion was possible.
      • get

        default <T2> java.util.Optional<T2> get​(@NonNull
                                                B bean,
                                                @NonNull
                                                Argument<T2> argument)
        Read the value and try to convert it to the given type.
        Type Parameters:
        T2 - The generic type
        Parameters:
        bean - The bean
        argument - The type
        Returns:
        The value if conversion was possible.
      • get

        default <T2> java.util.Optional<T2> get​(@NonNull
                                                B bean,
                                                @NonNull
                                                ArgumentConversionContext<T2> conversionContext)
        Read the value and try to convert it to the given type.
        Type Parameters:
        T2 - The generic type
        Parameters:
        bean - The bean
        conversionContext - The conversion context to use
        Returns:
        The value if conversion was possible.
      • get

        @Nullable
        default <T2> T2 get​(@NonNull
                            B bean,
                            @NonNull
                            java.lang.Class<T2> type,
                            @Nullable
                            T2 defaultValue)
        Read the value and try to convert it to the given type.
        Type Parameters:
        T2 - The generic type
        Parameters:
        bean - The bean
        type - The type
        defaultValue - The default value if conversion is not possible
        Returns:
        The value if conversion was possible.
      • hasSetterOrConstructorArgument

        default boolean hasSetterOrConstructorArgument()
        This method returns true if the property can be mutated either via copy constructor or bean setter.
        Returns:
        True if it is mutable
        Since:
        2.3.0
        See Also:
        withValue(Object, Object)
      • withValue

        default B withValue​(@NonNull
                            B bean,
                            @Nullable
                            T value)
        This method will attempt to modify the property or if this is a immutable type using a copy constructor to return a new instance with the new value.

        This differs from set(Object, Object) which will throw an exception if the property does not have a setter.

        • If the property is read-only but can be provided via constructor argument a new instance representing a copy of the bean is returned.
        • If the property is mutable then the passed instance is returned and set(Object, Object) invoked to mutate the property
        • If there is no way for the property to be mutated then an UnsupportedOperationException is thrown
        Parameters:
        bean - The bean
        value - The new value
        Returns:
        Either the existing instance or the property is mutable or a newly created instance via the copy constructor pattern.
        Throws:
        java.lang.UnsupportedOperationException - if the property cannot be mutated
        Since:
        2.3.0
      • set

        default void set​(@NonNull
                         B bean,
                         @Nullable
                         T value)
        Write the bean value.
        Parameters:
        bean - The bean
        value - The value to write
        Throws:
        java.lang.IllegalArgumentException - If either the bean type or value type are not correct
      • convertAndSet

        default void convertAndSet​(@NonNull
                                   B bean,
                                   @Nullable
                                   java.lang.Object value)
        Convert the value and set if on the bean using the default conversion service.
        Parameters:
        bean - The bean
        value - The value
        Throws:
        ConversionErrorException - If the value couldn't be converted
      • getType

        @NonNull
        java.lang.Class<T> getType()
        Returns:
        The property type.
      • isReadOnly

        default boolean isReadOnly()
        Returns:
        Whether the property is read-only
      • isWriteOnly

        default boolean isWriteOnly()
        Returns:
        Whether the property is write-only
      • isReadWrite

        default boolean isReadWrite()
        Whether the property can be written to and read from.
        Returns:
        True if it can.
      • getDeclaringType

        default java.lang.Class<B> getDeclaringType()
        The declaring type of the property.
        Returns:
        The type