Class ConverterImpl

java.lang.Object
com.hotels.beans.conversion.ConverterImpl
All Implemented Interfaces:
Converter

public class ConverterImpl
extends java.lang.Object
implements Converter
This class provides method for converting a primitive input into another.
  • Constructor Summary

    Constructors
    Constructor Description
    ConverterImpl()
    Default constructor.
  • Method Summary

    Modifier and Type Method Description
    <T,​ K> K convertValue​(T valueToConvert, java.lang.Class<K> targetClass)
    Converts a given primitive value into the given primitive type.
    java.util.Optional<java.util.function.Function<java.lang.Object,​java.lang.Object>> getConversionFunction​(java.lang.Class<?> sourceClass, java.lang.Class<?> targetClass)
    It provides a conversion function for the given primitive type into the other.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConverterImpl

      public ConverterImpl()
      Default constructor.
  • Method Details

    • getConversionFunction

      public java.util.Optional<java.util.function.Function<java.lang.Object,​java.lang.Object>> getConversionFunction​(java.lang.Class<?> sourceClass, java.lang.Class<?> targetClass)
      It provides a conversion function for the given primitive type into the other.
      Specified by:
      getConversionFunction in interface Converter
      Parameters:
      sourceClass - source field class
      targetClass - the destination field class
      Returns:
      an Optional containing the conversion function (if exists)
    • convertValue

      public <T,​ K> K convertValue​(T valueToConvert, java.lang.Class<K> targetClass)
      Converts a given primitive value into the given primitive type.
      Specified by:
      convertValue in interface Converter
      Type Parameters:
      T - the value to convert type
      K - the target object type
      Parameters:
      valueToConvert - the value to be converted
      targetClass - the destination field class
      Returns:
      the converted value