Class ConfigMatcher<T>

  • Type Parameters:
    T - the type of result produced by the mappers

    public class ConfigMatcher<T>
    extends java.lang.Object
    Groups ConfigMappers, allowing simple matchings by key or value.
    • Method Summary

      Modifier and Type Method Description
      java.util.Optional<T> loadFromKey​(java.lang.String key, ReadableMap config)
      Produce a result from the first mapper whose name equals (case ignored) the value associated to the given key, then store it into an optional.
      T loadFromKeyOrDefault​(java.lang.String key, ReadableMap config)
      Produce a result from the first mapper whose name equals (case ignored) the value associated to the given key
      java.util.Optional<T> loadFromValue​(java.lang.String value, ReadableMap config)
      Produce a result from the first mapper whose name equals (case ignored) the given value, then store it into an optional
      java.util.Collection<T> loadList​(java.lang.String key, ReadableMap config)
      Produce a list of results from the list of values associated to the given key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConfigMatcher

        public ConfigMatcher​(java.util.Collection<ConfigMapper<T>> mappers,
                             ConfigMapper<T> defaultMapper)
        Construct a ConfigMatcher with a default mapper, used in case loadFromKeyOrDefault(String, ReadableMap) fails to find any mapper.
        Parameters:
        mappers - the collection of mappers used for matchings
        defaultMapper - a default value when matching fails (may be null)
    • Method Detail

      • loadFromKey

        public java.util.Optional<T> loadFromKey​(java.lang.String key,
                                                 ReadableMap config)
        Produce a result from the first mapper whose name equals (case ignored) the value associated to the given key, then store it into an optional. If no mapper matches the given key, an empty optional is returned
        Parameters:
        key - the full path to the key
        config - the config loaded from the TOML file
        Returns:
        an optional containing the result created, if present
      • loadFromValue

        public java.util.Optional<T> loadFromValue​(java.lang.String value,
                                                   ReadableMap config)
        Produce a result from the first mapper whose name equals (case ignored) the given value, then store it into an optional
        Parameters:
        value - the given value
        config - the config loaded from the TOML file
        Returns:
        an optional containing the result created, if present
      • loadList

        public java.util.Collection<T> loadList​(java.lang.String key,
                                                ReadableMap config)
        Produce a list of results from the list of values associated to the given key. The algorithm tries to match every value found to a mapper stored, and adds the result created if it succeeds to do so.
        Parameters:
        key - the full path to the key corresponding to a list of string values
        config - the config loaded from the TOML file
        Returns:
        a potentially empty collection containing all the results successfully computed
      • loadFromKeyOrDefault

        public T loadFromKeyOrDefault​(java.lang.String key,
                                      ReadableMap config)
        Produce a result from the first mapper whose name equals (case ignored) the value associated to the given key
        Parameters:
        key - the full path to the key
        config - the config loaded from the TOML file
        Returns:
        the result created if present, otherwise the default value defined when constructing the object