Package 

Class DataReader

  • All Implemented Interfaces:

    
    public class DataReader
    
                        

    Utility to read data from Event data which is represented as Map<String, Object> in a type safe way.

    The value of an Event data key can be obtained in multiple ways:

    • The DataReader.optXyz(...) methods are typically the best choice for users. These methods return the value as an xyz. If the value is missing or is not an xyz, the method will return a default value. Implicit conversions between types are not performed, except between numeric types. No implicit conversions even between numeric types are performed when reading as Map or List.
    • The DataReader.getXyz(...) methods return the value as an xyz. If the value is missing or is not an xyz the method will throw. Implicit conversions between types are not performed, except between numeric types. No implicit conversions even between numeric types are performed when reading as Map or List.
    • Constructor Detail

    • Method Detail

      • getTypedMap

         static <T> Map<String, T> getTypedMap(Class<T> tClass, Map<String, out Object> map, String key)

        Gets the value for key from map as a Map<String, T>

        Parameters:
        tClass - Custom class
        map - Map map to fetch data
        key - String key to fetch
      • optTypedMap

         static <T> Map<String, T> optTypedMap(Class<T> tClass, Map<String, out Object> map, String key, Map<String, T> fallback)

        Gets the value for key from map as a Map<String, T> or returns default value

        Parameters:
        tClass - Custom class
        map - Map map to fetch data
        key - String key to fetch
        fallback - Map<String, T> value to return in case of failure.
      • getTypedList

         static <T> List<T> getTypedList(Class<T> tClass, Map<String, out Object> map, String key)

        Gets the value for key from map as a List<T>

        Parameters:
        tClass - Custom class
        map - Map map to fetch data
        key - String key to fetch
      • optTypedList

         static <T> List<T> optTypedList(Class<T> tClass, Map<String, out Object> map, String key, List<T> fallback)

        Gets the value for key from map as a List<T> or returns default value

        Parameters:
        tClass - Custom class
        map - Map map to fetch data
        key - String key to fetch
        fallback - List<T> value to return in case of failure.
      • optTypedListOfMap

         static <T> List<Map<String, T>> optTypedListOfMap(Class<T> tClass, Map<String, out Object> map, String key, List<Map<String, T>> fallback)

        Gets the value for key from map as a List<Map<String, T>> or returns default value

        Parameters:
        tClass - Custom class
        map - Map map to fetch data
        key - String key to fetch
        fallback - List<Map<String, T>> value to return in case of failure.
      • getBoolean

         static boolean getBoolean(Map<String, out Object> map, String key)

        Gets the value for key from map as a boolean

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
      • optBoolean

         static boolean optBoolean(Map<String, out Object> map, String key, boolean fallback)

        Gets the value for key from map as a boolean or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - boolean value to return in case of failure.
      • getInt

         static int getInt(Map<String, out Object> map, String key)

        Gets the value for key from map as an int

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
      • optInt

         static int optInt(Map<String, out Object> map, String key, int fallback)

        Gets the value for key from map as an int or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - int value to return in case of failure.
      • getLong

         static long getLong(Map<String, out Object> map, String key)

        Gets the value for key from map as an long

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
      • optLong

         static long optLong(Map<String, out Object> map, String key, long fallback)

        Gets the value for key from map as an long or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - long value to return in case of failure.
      • getFloat

         static float getFloat(Map<String, out Object> map, String key)

        Gets the value for key from map as an float

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
      • optFloat

         static float optFloat(Map<String, out Object> map, String key, float fallback)

        Gets the value for key from map as an float or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - float value to return in case of failure.
      • getDouble

         static double getDouble(Map<String, out Object> map, String key)

        Gets the value for key from map as an double

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
      • optDouble

         static double optDouble(Map<String, out Object> map, String key, double fallback)

        Gets the value for key from map as an double or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - double value to return in case of failure.
      • getString

         static String getString(Map<String, out Object> map, String key)

        Gets the value for key from map as an String

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
      • optString

         static String optString(Map<String, out Object> map, String key, String fallback)

        Gets the value for key from map as a String or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - String value to return in case of failure.
      • optStringMap

         static Map<String, String> optStringMap(Map<String, out Object> map, String key, Map<String, String> fallback)

        Gets the value for key from map as a Map<String, String> or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - Map<String, String> value to return in case of failure.
      • optStringList

         static List<String> optStringList(Map<String, out Object> map, String key, List<String> fallback)

        Gets the value for key from map as a List<String> or returns default value

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        fallback - List<String> value to return in case of failure.