Class MetadataHandler.Builder<C>

  • Type Parameters:
    C - the context type.
    Enclosing class:
    MetadataHandler<C>

    public static final class MetadataHandler.Builder<C>
    extends Object
    Builder for a map-based MetadataHandler which allows handlers to be associated with individual callbacks.
    • Method Detail

      • addHandler

        @CanIgnoreReturnValue
        public <T> MetadataHandler.Builder<C> addHandler​(FloggerMetadataKey<T> key,
                                                         MetadataHandler.ValueHandler<? super T,​? super C> handler)
        Registers a value handler for the specified key, replacing any previously registered value.
        Type Parameters:
        T - the key/value type.
        Parameters:
        key - the key for which the handler should be invoked (can be a repeated key).
        handler - the value handler to be invoked for every value associated with the key.
        Returns:
        the builder instance for chaining.
      • addRepeatedHandler

        @CanIgnoreReturnValue
        public <T> MetadataHandler.Builder<C> addRepeatedHandler​(FloggerMetadataKey<? extends T> key,
                                                                 MetadataHandler.RepeatedValueHandler<T,​? super C> handler)
        Registers a repeated value handler for the specified key, replacing any previously registered value.
        Type Parameters:
        T - the key/value type.
        Parameters:
        key - the repeated key for which the handler should be invoked.
        handler - the repeated value handler to be invoked once for all associated values.
        Returns:
        the builder instance for chaining.
      • ignoring

        @CanIgnoreReturnValue
        public MetadataHandler.Builder<C> ignoring​(FloggerMetadataKey<?> key,
                                                   FloggerMetadataKey<?>... rest)
        Registers "no op" handlers for the given keys, resulting in their values being ignored.
        Parameters:
        key - a key to ignore in the builder.
        rest - additional keys to ignore in the builder.
        Returns:
        the builder instance for chaining.
      • ignoring

        @CanIgnoreReturnValue
        public MetadataHandler.Builder<C> ignoring​(Iterable<FloggerMetadataKey<?>> keys)
        Registers "no op" handlers for the given keys, resulting in their values being ignored.
        Parameters:
        keys - the keys to ignore in the builder.
        Returns:
        the builder instance for chaining.
      • removeHandlers

        @CanIgnoreReturnValue
        public MetadataHandler.Builder<C> removeHandlers​(FloggerMetadataKey<?> key,
                                                         FloggerMetadataKey<?>... rest)
        Removes any existing handlers for the given keys, returning them to the default handler(s). This method is useful when making several handlers with different mappings from a single builder.
        Parameters:
        key - a key to remove from the builder.
        rest - additional keys to remove from the builder.
        Returns:
        the builder instance for chaining.
      • build

        public MetadataHandler<C> build()
        Returns the immutable, map-based metadata handler.