Class Mapper

java.lang.Object
com.apptasticsoftware.rssreader.util.Mapper

public final class Mapper extends Object
Provides methods for mapping field
  • Method Details

    • mapBoolean

      public static void mapBoolean(String text, Consumer<Boolean> func)
      Maps a boolean text value (true, false, no or yes) to a boolean field. Text value can be in any casing.
      Parameters:
      text - text value
      func - boolean setter method
    • mapInteger

      public static void mapInteger(String text, Consumer<Integer> func)
      Maps a integer text value to a integer field.
      Parameters:
      text - text value
      func - integer setter method
    • mapLong

      public static void mapLong(String text, Consumer<Long> func)
      Maps a long text value to a long field.
      Parameters:
      text - text value
      func - long setter method
    • mapIfEmpty

      public static <T> void mapIfEmpty(String text, Supplier<T> getter, Consumer<String> setter)
      Map value if field has not been mapped before
      Type Parameters:
      T - type
      Parameters:
      text - value to map
      getter - getter to check if field is empty
      setter - setter to set value
    • createIfNull

      public static <T> T createIfNull(Supplier<Optional<T>> getter, Consumer<T> setter, Supplier<T> factory)
      Create a new instance if a getter returns optional empty and assigns the field the new instance.
      Type Parameters:
      T - any class
      Parameters:
      getter - getter method
      setter - setter method
      factory - factory for creating a new instance if field is not set before
      Returns:
      existing or new instance
    • createIfNullOptional

      public static <T> Optional<T> createIfNullOptional(Supplier<Optional<T>> getter, Consumer<T> setter, Supplier<T> factory)
      Create a new instance if a getter returns optional empty and assigns the field the new instance.
      Type Parameters:
      T - any class
      Parameters:
      getter - getter method
      setter - setter method
      factory - factory for creating a new instance if field is not set before
      Returns:
      existing or new instance
    • emptyListIfNull

      public static <T> List<T> emptyListIfNull(List<T> list)
      Returns an empty list if the provided list is null.
      Type Parameters:
      T - the type of items in the list
      Parameters:
      list - the list to check
      Returns:
      an empty list if the provided list is null, otherwise returns the provided list