Class ConfigMapLoader
java.lang.Object
me.bristermitten.mittenlib.config.ConfigMapLoader
Used in generated code to help with the loading of config maps
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<T> load(Map<String, Object> map, String key, Class<T> type, T defaultValue, Function<Map<String, Object>, T> fromMap) Get a value from a map, or return an empty optional if the value is null This tries a few different ways to load the value: Cast if it is an instance oftypeIf it is aMap, usefromMapUse the default value, if presentstatic RuntimeExceptionthrowNotFound(String fieldName, String typeName, Class<?> enclosingClass, String keyName) Deprecated.
-
Method Details
-
load
public static <T> Optional<T> load(Map<String, Object> map, String key, Class<T> type, @Nullable T defaultValue, Function<Map<String, throws IllegalArgumentExceptionObject>, T> fromMap) Get a value from a map, or return an empty optional if the value is null This tries a few different ways to load the value:- Cast if it is an instance of
type - If it is a
Map, usefromMap - Use the default value, if present
If all of them fail, an
IllegalArgumentExceptionis thrown- Type Parameters:
T- the type to cast the value to- Parameters:
map- the map to get the value fromkey- the key to get the value withtype- the type to cast the value todefaultValue- the default value to use if the value is nullfromMap- the function to use to load the value from a map structure- Returns:
- the value, or an empty optional if the value is null
- Throws:
IllegalArgumentException- if all the ways to load the value fail
- Cast if it is an instance of
-
throwNotFound
@Deprecated @InlineMe(replacement="ConfigLoadingErrors.notFoundException(fieldName, typeName, enclosingClass, keyName)", imports="me.bristermitten.mittenlib.config.exception.ConfigLoadingErrors") public static RuntimeException throwNotFound(String fieldName, String typeName, Class<?> enclosingClass, String keyName) Creates an exception to use when a value cannot be deserialized as it is not found (i.e. is null)- Parameters:
fieldName- the name of the field that is trying to be deserializedtypeName- the name of the type that is trying to be deserializedenclosingClass- the name of the enclosing class- Returns:
- the exception to throw
-
ConfigLoadingErrors.notFoundException(String, String, Class, String)