Class MetadataHandler.Builder<C>
- java.lang.Object
-
- com.google.common.flogger.backend.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-basedMetadataHandlerwhich allows handlers to be associated with individual callbacks.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> MetadataHandler.Builder<C>addHandler(MetadataKey<T> key, MetadataHandler.ValueHandler<? super T,? super C> handler)Registers a value handler for the specified key, replacing any previously registered value.<T> MetadataHandler.Builder<C>addRepeatedHandler(MetadataKey<? extends T> key, MetadataHandler.RepeatedValueHandler<T,? super C> handler)Registers a repeated value handler for the specified key, replacing any previously registered value.MetadataHandler<C>build()Returns the immutable, map-based metadata handler.MetadataHandler.Builder<C>ignoring(MetadataKey<?> key, MetadataKey<?>... rest)Registers "no op" handlers for the given keys, resulting in their values being ignored.MetadataHandler.Builder<C>ignoring(Iterable<MetadataKey<?>> keys)Registers "no op" handlers for the given keys, resulting in their values being ignored.MetadataHandler.Builder<C>removeHandlers(MetadataKey<?> key, MetadataKey<?>... rest)Removes any existing handlers for the given keys, returning them to the default handler(s).MetadataHandler.Builder<C>setDefaultRepeatedHandler(MetadataHandler.RepeatedValueHandler<Object,? super C> defaultHandler)Sets a handler for any unknown repeated keys which allows values to be processed via a genericIterator.
-
-
-
Method Detail
-
setDefaultRepeatedHandler
@CanIgnoreReturnValue public MetadataHandler.Builder<C> setDefaultRepeatedHandler(MetadataHandler.RepeatedValueHandler<Object,? super C> defaultHandler)
Sets a handler for any unknown repeated keys which allows values to be processed via a genericIterator. To handle repeated values against a known key with their expected type, register a handler viaaddRepeatedHandler(MetadataKey,RepeatedValueHandler).Note that if a repeated key is associated with an individual value handler (i.e. via
addHandler(MetadataKey,ValueHandler)), then that will be used in preference to the default handler set here.- Parameters:
defaultHandler- the default handler for unknown repeated keys/values.- Returns:
- the builder instance for chaining.
-
addHandler
@CanIgnoreReturnValue public <T> MetadataHandler.Builder<C> addHandler(MetadataKey<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(MetadataKey<? 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(MetadataKey<?> key, MetadataKey<?>... 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<MetadataKey<?>> 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(MetadataKey<?> key, MetadataKey<?>... 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.
-
-