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
        Returns:

        Map<String, T> Map associated with key or null if key is not present in map

      • 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.
        Returns:

        Map<String, T> Map associated with key, or fallback if value is not gettable as a Map<String, T>

      • 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
        Returns:

        List<T> List associated with key or null if key is not present in map

      • 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.
        Returns:

        List<T> List associated with key, or fallback if value is not gettable as a List<T>

      • getTypedListOfMap

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

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

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

        List<Map<String, T>> List associated with key or null if key is not present in map

      • 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.
        Returns:

        List<Map<String, T>> List associated with key, or fallback if value is not gettable as a List<Map<String, T>>

      • 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
        Returns:

        boolean value associated with key

      • 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.
        Returns:

        boolean value associated with key, or fallback if value is not gettable as a boolean

      • 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
        Returns:

        int value associated with key

      • 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.
        Returns:

        int value associated with key, or fallback if value is not gettable as a int

      • 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
        Returns:

        long value associated with key

      • 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.
        Returns:

        long value associated with key, or fallback if value is not gettable as a long

      • 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
        Returns:

        float value associated with key

      • 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.
        Returns:

        float value associated with key, or fallback if value is not gettable as a float

      • 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
        Returns:

        double value associated with key

      • 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.
        Returns:

        double value associated with key, or fallback if value is not gettable as a double

      • 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
        Returns:

        String value associated with key or null if key is not present in map

      • 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.
        Returns:

        String value associated with key, or fallback if value is not gettable as a String

      • getStringMap

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

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

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        Returns:

        Map<String, String> Map associated with key or null if key is not present in map

      • 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.
        Returns:

        Map<String, String> value associated with key, or fallback if value is not gettable as a Map<String, String>

      • getStringList

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

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

        Parameters:
        map - Map map to fetch data
        key - String key to fetch
        Returns:

        List<String> List associated with key or null if key is not present in map

      • 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.
        Returns:

        List<String> List associated with key, or fallback if value is not gettable as a List<String>