Class Converters


  • public class Converters
    extends java.lang.Object
    Class to convert various types for easier storage in Room DB.
    Author:
    Evan Voogd
    • Constructor Summary

      Constructors 
      Constructor Description
      Converters()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String fromArrayList​(java.util.ArrayList<java.lang.Long> list)
      Convert ArrayList of Longs (used for IDs) to a String, useful for storing parent/child relations
      static java.lang.Long fromLocalDate​(org.threeten.bp.LocalDate date)
      Convert LocalDate to Long for easy storing of LocalDate fields in Room DB.
      static java.lang.Long fromLocalDateTime​(org.threeten.bp.LocalDateTime date)
      Convert LocalDateTime to Long for easy storing of LocalDateTime fields in Room DB.
      static java.util.ArrayList<java.lang.Long> fromString​(java.lang.String value)
      Convert String of Longs (used for IDs) to an ArrayList, useful for storing parent/child relations
      static org.threeten.bp.LocalDate toLocalDate​(java.lang.Long dateLong)
      Convert Long to LocalDate for easy storing of LocalDate fields in Room DB.
      static org.threeten.bp.LocalDateTime toLocalDateTime​(java.lang.Long dateLong)
      Convert Long to LocalDateTime for easy storing of LocalDateTime fields in Room DB.
      • Methods inherited from class java.lang.Object

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

      • Converters

        public Converters()
    • Method Detail

      • toLocalDate

        public static org.threeten.bp.LocalDate toLocalDate​(java.lang.Long dateLong)
        Convert Long to LocalDate for easy storing of LocalDate fields in Room DB.
        Parameters:
        dateLong - The long returned from LocalDate.toEpochDay() stored in the Room DB.
        Returns:
        the LocalDate associated with the long stored in the RoomDB.
      • fromLocalDate

        public static java.lang.Long fromLocalDate​(org.threeten.bp.LocalDate date)
        Convert LocalDate to Long for easy storing of LocalDate fields in Room DB.
        Parameters:
        date - The day to be converted to a long
        Returns:
        A long based on the day
      • toLocalDateTime

        public static org.threeten.bp.LocalDateTime toLocalDateTime​(java.lang.Long dateLong)
        Convert Long to LocalDateTime for easy storing of LocalDateTime fields in Room DB.
        Parameters:
        dateLong - The long returned from ofEpochSecond stored in the Room DB.
        Returns:
        the LocalDate associated with the long stored in the RoomDB.
      • fromLocalDateTime

        public static java.lang.Long fromLocalDateTime​(org.threeten.bp.LocalDateTime date)
        Convert LocalDateTime to Long for easy storing of LocalDateTime fields in Room DB.
        Parameters:
        date - The day to be converted to a long
        Returns:
        A long based on the day
      • fromString

        public static java.util.ArrayList<java.lang.Long> fromString​(java.lang.String value)
        Convert String of Longs (used for IDs) to an ArrayList, useful for storing parent/child relations
        Parameters:
        value - A comma separated list of Longs
        Returns:
        An ArrayList of Longs
      • fromArrayList

        public static java.lang.String fromArrayList​(java.util.ArrayList<java.lang.Long> list)
        Convert ArrayList of Longs (used for IDs) to a String, useful for storing parent/child relations
        Parameters:
        list - An arraylist of longs
        Returns:
        A comma separated list of longs