Class DataReader
-
- All Implemented Interfaces:
public class DataReaderUtility to read data from
Eventdata which is represented asMap<String, Object>in a type safe way.The value of an
Eventdata key can be obtained in multiple ways:- The
DataReader.optXyz(...)methods are typically the best choice for users. These methods return the value as anxyz. If the value is missing or is not anxyz, 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 asMaporList. - The
DataReader.getXyz(...)methods return the value as anxyz. If the value is missing or is not anxyzthe 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 asMaporList.
-
-
Method Summary
Modifier and Type Method Description static <T> Map<String, T>getTypedMap(Class<T> tClass, Map<String, out Object> map, String key)Gets the value for keyfrommapas aMap<String, T>static <T> Map<String, T>optTypedMap(Class<T> tClass, Map<String, out Object> map, String key, Map<String, T> fallback)Gets the value for keyfrommapas aMap<String, T>or returns default valuestatic <T> List<T>getTypedList(Class<T> tClass, Map<String, out Object> map, String key)Gets the value for keyfrommapas aList<T>static <T> List<T>optTypedList(Class<T> tClass, Map<String, out Object> map, String key, List<T> fallback)Gets the value for keyfrommapas aList<T>or returns default valuestatic <T> List<Map<String, T>>getTypedListOfMap(Class<T> tClass, Map<String, out Object> map, String key)Gets the value for keyfrommapas aList<Map<String, T>>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 keyfrommapas aList<Map<String, T>>or returns default valuestatic booleangetBoolean(Map<String, out Object> map, String key)Gets the value for keyfrommapas abooleanstatic booleanoptBoolean(Map<String, out Object> map, String key, boolean fallback)Gets the value for keyfrommapas abooleanor returns default valuestatic intgetInt(Map<String, out Object> map, String key)Gets the value for keyfrommapas anintstatic intoptInt(Map<String, out Object> map, String key, int fallback)Gets the value for keyfrommapas anintor returns default valuestatic longgetLong(Map<String, out Object> map, String key)Gets the value for keyfrommapas anlongstatic longoptLong(Map<String, out Object> map, String key, long fallback)Gets the value for keyfrommapas anlongor returns default valuestatic floatgetFloat(Map<String, out Object> map, String key)Gets the value for keyfrommapas anfloatstatic floatoptFloat(Map<String, out Object> map, String key, float fallback)Gets the value for keyfrommapas anfloator returns default valuestatic doublegetDouble(Map<String, out Object> map, String key)Gets the value for keyfrommapas andoublestatic doubleoptDouble(Map<String, out Object> map, String key, double fallback)Gets the value for keyfrommapas andoubleor returns default valuestatic StringgetString(Map<String, out Object> map, String key)Gets the value for keyfrommapas anStringstatic StringoptString(Map<String, out Object> map, String key, String fallback)Gets the value for keyfrommapas aStringor returns default valuestatic Map<String, String>getStringMap(Map<String, out Object> map, String key)Gets the value for keyfrommapas aMap<String, String>static Map<String, String>optStringMap(Map<String, out Object> map, String key, Map<String, String> fallback)Gets the value for keyfrommapas aMap<String, String>or returns default valuestatic List<String>getStringList(Map<String, out Object> map, String key)Gets the value for keyfrommapas aList<String>static List<String>optStringList(Map<String, out Object> map, String key, List<String> fallback)Gets the value for keyfrommapas aList<String>or returns default value-
-
Method Detail
-
getTypedMap
static <T> Map<String, T> getTypedMap(Class<T> tClass, Map<String, out Object> map, String key)
Gets the value for
keyfrommapas aMap<String, T>- Parameters:
tClass- Custom classmap-Mapmap to fetch datakey-Stringkey to fetch- Returns:
Map<String, T>Map associated withkeyor null ifkeyis not present inmap
-
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
keyfrommapas aMap<String, T>or returns default value- Parameters:
tClass- Custom classmap-Mapmap to fetch datakey-Stringkey to fetchfallback-Map<String, T>value to return in case of failure.- Returns:
Map<String, T>Map associated withkey, orfallbackif value is not gettable as aMap<String, T>
-
getTypedList
static <T> List<T> getTypedList(Class<T> tClass, Map<String, out Object> map, String key)
Gets the value for
keyfrommapas aList<T>- Parameters:
tClass- Custom classmap-Mapmap to fetch datakey-Stringkey to fetch- Returns:
List<T>List associated withkeyor null ifkeyis not present inmap
-
optTypedList
static <T> List<T> optTypedList(Class<T> tClass, Map<String, out Object> map, String key, List<T> fallback)
Gets the value for
keyfrommapas aList<T>or returns default value- Parameters:
tClass- Custom classmap-Mapmap to fetch datakey-Stringkey to fetchfallback-List<T>value to return in case of failure.- Returns:
List<T>List associated withkey, orfallbackif value is not gettable as aList<T>
-
getTypedListOfMap
static <T> List<Map<String, T>> getTypedListOfMap(Class<T> tClass, Map<String, out Object> map, String key)
Gets the value for
keyfrommapas aList<Map<String, T>>- Parameters:
tClass- Custom classmap-Mapmap to fetch datakey-Stringkey to fetch- Returns:
List<Map<String, T>>List associated withkeyor null ifkeyis not present inmap
-
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
keyfrommapas aList<Map<String, T>>or returns default value- Parameters:
tClass- Custom classmap-Mapmap to fetch datakey-Stringkey to fetchfallback-List<Map<String, T>>value to return in case of failure.- Returns:
List<Map<String, T>>List associated withkey, orfallbackif value is not gettable as aList<Map<String, T>>
-
getBoolean
static boolean getBoolean(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas aboolean- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
booleanvalue associated withkey
-
optBoolean
static boolean optBoolean(Map<String, out Object> map, String key, boolean fallback)
Gets the value for
keyfrommapas abooleanor returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-booleanvalue to return in case of failure.- Returns:
booleanvalue associated withkey, orfallbackif value is not gettable as aboolean
-
getInt
static int getInt(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas anint- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
intvalue associated withkey
-
optInt
static int optInt(Map<String, out Object> map, String key, int fallback)
Gets the value for
keyfrommapas anintor returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-intvalue to return in case of failure.- Returns:
intvalue associated withkey, orfallbackif value is not gettable as aint
-
getLong
static long getLong(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas anlong- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
longvalue associated withkey
-
optLong
static long optLong(Map<String, out Object> map, String key, long fallback)
Gets the value for
keyfrommapas anlongor returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-longvalue to return in case of failure.- Returns:
longvalue associated withkey, orfallbackif value is not gettable as along
-
getFloat
static float getFloat(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas anfloat- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
floatvalue associated withkey
-
optFloat
static float optFloat(Map<String, out Object> map, String key, float fallback)
Gets the value for
keyfrommapas anfloator returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-floatvalue to return in case of failure.- Returns:
floatvalue associated withkey, orfallbackif value is not gettable as afloat
-
getDouble
static double getDouble(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas andouble- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
doublevalue associated withkey
-
optDouble
static double optDouble(Map<String, out Object> map, String key, double fallback)
Gets the value for
keyfrommapas andoubleor returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-doublevalue to return in case of failure.- Returns:
doublevalue associated withkey, orfallbackif value is not gettable as adouble
-
getString
static String getString(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas anString- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
Stringvalue associated withkeyor null ifkeyis not present inmap
-
optString
static String optString(Map<String, out Object> map, String key, String fallback)
Gets the value for
keyfrommapas aStringor returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-Stringvalue to return in case of failure.- Returns:
Stringvalue associated withkey, orfallbackif value is not gettable as aString
-
getStringMap
static Map<String, String> getStringMap(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas aMap<String, String>- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
Map<String, String>Map associated withkeyor null ifkeyis not present inmap
-
optStringMap
static Map<String, String> optStringMap(Map<String, out Object> map, String key, Map<String, String> fallback)
Gets the value for
keyfrommapas aMap<String, String>or returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-Map<String, String>value to return in case of failure.- Returns:
Map<String, String>value associated withkey, orfallbackif value is not gettable as aMap<String, String>
-
getStringList
static List<String> getStringList(Map<String, out Object> map, String key)
Gets the value for
keyfrommapas aList<String>- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetch- Returns:
List<String>List associated withkeyor null ifkeyis not present inmap
-
optStringList
static List<String> optStringList(Map<String, out Object> map, String key, List<String> fallback)
Gets the value for
keyfrommapas aList<String>or returns default value- Parameters:
map-Mapmap to fetch datakey-Stringkey to fetchfallback-List<String>value to return in case of failure.- Returns:
List<String>List associated withkey, orfallbackif value is not gettable as aList<String>
-
-
-
-