Class Metadata
- java.lang.Object
-
- com.google.common.flogger.backend.Metadata
-
- Direct Known Subclasses:
ContextMetadata
public abstract class Metadata extends java.lang.Object
A sequence of metadata key/value pairs which can be associated to a log statement, either directly via methods in the fluent API, of as part of a scoped logging context.Metadata keys can "single valued" or "repeating" based on
MetadataKey.canRepeat
, but it is permitted for aMetadata
implementation to retain multiple single valued keys, and in that situation the key at the largest index is the one which should be used.Multiple
Metadata
instances can be merged, in order, to provide a final sequence for a log statement. WhenMetadata
instance are merged, the result is just the concatenation of the sequence of key/value pairs, and this is what results in the potential for mutliple single valued keys to exist.If the value of a single valued key is required, the
findValue(MetadataKey)
method should be used to look it up. For all other metadata processing, aMetadataProcessor
should be created to ensure that scope and log site metadata can be merged correctly.
-
-
Constructor Summary
Constructors Constructor Description Metadata()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Metadata
empty()
Returns an immutableMetadata
that has no items.abstract <T> T
findValue(MetadataKey<T> key)
Returns the first value for the given single valued metadata key, or null if it does not exist.abstract MetadataKey<?>
getKey(int n)
Returns the key for the Nth piece of metadata.abstract java.lang.Object
getValue(int n)
Returns the non-null value for the Nth piece of metadata.abstract int
size()
Returns the number of key/value pairs for this instance.
-
-
-
Method Detail
-
size
public abstract int size()
Returns the number of key/value pairs for this instance.
-
getKey
public abstract MetadataKey<?> getKey(int n)
Returns the key for the Nth piece of metadata.- Throws:
java.lang.IndexOutOfBoundsException
- if eithern < 0
or {n >= getCount()}.
-
getValue
public abstract java.lang.Object getValue(int n)
Returns the non-null value for the Nth piece of metadata.- Throws:
java.lang.IndexOutOfBoundsException
- if eithern < 0
or {n >= getCount()}.
-
findValue
@NullableDecl public abstract <T> T findValue(MetadataKey<T> key)
Returns the first value for the given single valued metadata key, or null if it does not exist.- Throws:
java.lang.NullPointerException
- ifkey
isnull
.
-
-