com.holonplatform.core.property

## Interface PropertyValueConverter<TYPE,MODEL>

- Type Parameters:
    `TYPE` - Property value type
    `MODEL` - Model data type
  All Superinterfaces:
    Serializable
  All Known Subinterfaces:
    CollectionPropertyValueConverter<TYPE,C,MODEL>

      public interface PropertyValueConverter<TYPE,MODEL>
      extends Serializable

  Performs conversion between a `Property` type and a data model type, in both directions.

  The `fromModel(Object, Property)` and `toModel(Object, Property)` methods should be symmetric, so that chaining these together returns the original result for all inputs.

  Since:
    5.0.0
  See Also:
    `Property`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `PropertyValueConverter.PropertyConversionException` Exception thrown when a property value conversion fails.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <E extends Enum<E>> PropertyValueConverter<E,String>` | `enumByName()` Create a `PropertyValueConverter` which converts property values of given `enum` type into their corresponding name `String` value and vice-versa.
    `static <E extends Enum<E>> PropertyValueConverter<E,Integer>` | `enumByOrdinal()` Create a `PropertyValueConverter` which converts property values of given `enum` type into their corresponding ordinal `Integer` value and vice-versa.
    `TYPE` | `fromModel(MODEL value, Property<TYPE> property)` Convert given value from model data type to property value type
    `Class<MODEL>` | `getModelType()` Get the model data type
    `Class<TYPE>` | `getPropertyType()` Get the property type
    `static PropertyValueConverter<LocalDate,Date>` | `localDate()` Create a `PropertyValueConverter` to convert `Date` model values into `LocalDate` type.
    `static PropertyValueConverter<LocalDateTime,Date>` | `localDateTime()` Create a `PropertyValueConverter` to convert `Date` model values into `LocalDateTime` type.
    `static <N extends Number> PropertyValueConverter<Boolean,N>` | `numericBoolean(Class<N> modelType)` Create a numeric boolean `PropertyValueConverter` which converts property values of numeric type into boolean values using the following convention: `null` or `0` numeric values will be converted as `false` boolean values, any other value will be converted as boolean `true` value.
    `MODEL` | `toModel(TYPE value, Property<TYPE> property)` Convert given value from property value type to model data type

- - ### Method Detail

    - #### fromModel

          TYPE fromModel(MODEL value,
                         Property<TYPE> property)
                  throws PropertyValueConverter.PropertyConversionException

      Convert given value from model data type to property value type
      Parameters:
        `value` - Value to convert
        `property` - Target property
      Returns:
        Value converted to property value type
      Throws:
        `PropertyValueConverter.PropertyConversionException` - Error converting value

    - #### toModel

          MODEL toModel(TYPE value,
                        Property<TYPE> property)
                 throws PropertyValueConverter.PropertyConversionException

      Convert given value from property value type to model data type
      Parameters:
        `value` - Value to convert
        `property` - Target property
      Returns:
        Value converted to model data type
      Throws:
        `PropertyValueConverter.PropertyConversionException` - Error converting value

    - #### getPropertyType

          Class<TYPE> getPropertyType()

      Get the property type
      Returns:
        Property type

    - #### getModelType

          Class<MODEL> getModelType()

      Get the model data type
      Returns:
        Model data type

    - #### numericBoolean

          static <N extends Number> PropertyValueConverter<Boolean,N> numericBoolean(Class<N> modelType)

      Create a numeric boolean `PropertyValueConverter` which converts property values of numeric type into boolean values using the following convention: `null` or `0` numeric values will be converted as `false` boolean values, any other value will be converted as boolean `true` value.
      Type Parameters:
        `N` - Concrete Number model type
      Parameters:
        `modelType` - Property value type (numeric)
      Returns:
        Numeric boolean converter

    - #### enumByOrdinal

          static <E extends Enum<E>> PropertyValueConverter<E,Integer> enumByOrdinal()

      Create a `PropertyValueConverter` which converts property values of given `enum` type into their corresponding ordinal `Integer` value and vice-versa.
      Type Parameters:
        `E` - Enum type
      Returns:
        Enum by ordinal converter

    - #### enumByName

          static <E extends Enum<E>> PropertyValueConverter<E,String> enumByName()

      Create a `PropertyValueConverter` which converts property values of given `enum` type into their corresponding name `String` value and vice-versa.
      Type Parameters:
        `E` - Enum type
      Returns:
        Enum by name converter

    - #### localDate

          static PropertyValueConverter<LocalDate,Date> localDate()

      Create a `PropertyValueConverter` to convert `Date` model values into `LocalDate` type.
      Returns:
        LocalDate/Date value converter

    - #### localDateTime

          static PropertyValueConverter<LocalDateTime,Date> localDateTime()

      Create a `PropertyValueConverter` to convert `Date` model values into `LocalDateTime` type.
      Returns:
        LocalDateTime/Date value converter

Copyright © 2019 The Holon Platform. All rights reserved.