Interface TypeLiaison.Agent<V>

Type Parameters:
V - the value type being handled
Enclosing interface:
TypeLiaison

public static interface TypeLiaison.Agent<V>
An agent that is ready to handle matters relating to a type
  • Method Details

    • loadDefaultValues

      @SideEffectFree default @Nullable DefaultValues<V> loadDefaultValues(@NonNull TypeLiaison.DefaultInit<V> defaultInit)
      Gets default values.

      This function is called for the return type of each configuration interface method, on the agent corresponding to that return type.

      Default values are often extracted from annotations. Method-level annotations are available via the provided TypeLiaison.DefaultInit.methodAnnotations().

      Note that this function does NOT handle the use of default methods to provide default values. This function provides default values before a default method can possibly do so; this function returning a non-null value will override the result of the default method if one exists.

      Parameters:
      defaultInit - the init context
      Returns:
      the default values, or null if no defaults are available
      Throws:
      DeveloperMistakeException - if a library usage failure happened
    • makeSerializer

      @SideEffectFree @NonNull SerializeDeserialize<V> makeSerializer()
      Makes a serializer for the type. After the serializer is made, it will be permanently bound to the type and can be re-used in the configuration structure.
      Returns:
      the serializer
    • matchOnToken

      @SideEffectFree static <V, R> @Nullable TypeLiaison.Agent<R> matchOnToken(@NonNull TypeToken<R> token, @NonNull Class<V> matchWith, @NonNull Supplier<@NonNull TypeLiaison.Agent<V>> factory)
      A convenience API for cast-free, generic-safe agent creation, given raw type V.

      If the provided token matches the given matchWith in raw type, then the factory is queried to return an agent. If the raw type does not match, null is returned.

      Because Java does not have a good way to match on generic parameters, this function provides a helpful workaround.

      Type Parameters:
      V - the token type
      R - the raw type to look for
      Parameters:
      token - the token for whom an agent might be provided for; annotations on this token are ignored
      matchWith - the raw type to check if the token matches
      factory - the supplier to make the agent assuming the token matches the given raw type
      Returns:
      the created agent if successful, or null if the token has a diffferent type