Class Tags
- java.lang.Object
-
- io.spine.logging.flogger.context.Tags
-
public final class Tags extends Object
Immutable tags which can be attached to log statements via platform specific injection mechanisms.A tag is either a "simple" tag, added via
Tags.Builder.addTag(String)or a tag with a value, added via one of theaddTag(name,value)methods. When thinking of tags as aMap<String, Set<Object>>, the value of a "simple" tag is the empty set.Tag values can be of several simple types and are held in a stable, sorted order within a
Tagsinstance. In other words it never matters in which order twoTagsinstances are merged.When tags are merged, the result is the union of the values. This is easier to explain When thinking of tags as a
Map<String, Set<Object>>, where "merging" means taking the union of theSetassociated with the tag name. In particular, for a given tag name:- Adding the same value for a given tag twice has no additional effect.
- Adding a simple tag twice has no additional effect.
- Adding a tag with a value is also implicitly like adding a simple tag with the same name.
The
toString()implementation of this class provides a human readable, machine parsable representation of the tags.- See Also:
- Original Java code of Google Flogger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTags.BuilderA mutable builder for tags.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Set<Object>>asMap()Returns an immutable map containing the tag values.static Tags.Builderbuilder()Returns a new builder for adding tags.static Tagsempty()Returns the immutable empty tags instance.booleanequals(@Nullable Object obj)inthashCode()booleanisEmpty()Returns whether this instance is empty.Tagsmerge(Tags other)Merges two tags instances, combining values for any name contained in both.static Tagsof(String name, boolean value)Returns a single tag without needing to use the builder API.static Tagsof(String name, double value)Returns a single tag without needing to use the builder API.static Tagsof(String name, long value)Returns a single tag without needing to use the builder API.static Tagsof(String name, String value)Returns a single tag without needing to use the builder API.StringtoString()Returns human readable representation of the tags.
-
-
-
Method Detail
-
builder
public static Tags.Builder builder()
Returns a new builder for adding tags.
-
empty
public static Tags empty()
Returns the immutable empty tags instance.
-
of
public static Tags of(String name, String value)
Returns a single tag without needing to use the builder API. Where multiple tags are needed, it is always better to use the builder directly.
-
of
public static Tags of(String name, boolean value)
Returns a single tag without needing to use the builder API. Where multiple tags are needed, it is always better to use the builder directly.
-
of
public static Tags of(String name, long value)
Returns a single tag without needing to use the builder API. Where multiple tags are needed, it is always better to use the builder directly.
-
of
public static Tags of(String name, double value)
Returns a single tag without needing to use the builder API. Where multiple tags are needed, it is always better to use the builder directly.
-
isEmpty
public boolean isEmpty()
Returns whether this instance is empty.
-
merge
public Tags merge(Tags other)
Merges two tags instances, combining values for any name contained in both.
-
-