Class ConfigMapLoader

java.lang.Object
me.bristermitten.mittenlib.config.ConfigMapLoader

public class ConfigMapLoader extends Object
Used in generated code to help with the loading of config maps
  • Method Details

    • load

      public static <T> Optional<T> load(Map<String,Object> map, String key, Class<T> type, @Nullable T defaultValue, Function<Map<String,Object>, T> fromMap) throws IllegalArgumentException
      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:
      1. Cast if it is an instance of type
      2. If it is a Map, use fromMap
      3. Use the default value, if present

      If all of them fail, an IllegalArgumentException is thrown

      Type Parameters:
      T - the type to cast the value to
      Parameters:
      map - the map to get the value from
      key - the key to get the value with
      type - the type to cast the value to
      defaultValue - the default value to use if the value is null
      fromMap - 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
    • 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 deserialized
      typeName - the name of the type that is trying to be deserialized
      enclosingClass - the name of the enclosing class
      Returns:
      the exception to throw