Top Description Inners Fields Constructors Methods
io.micrometer.common

public final Class KeyValues

extends Object
implements Iterable<KeyValue>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
io.micrometer.common.lang.Nullable, java.util.*, java.util.function.Function, java.util.stream.Stream, .StreamSupport

An immutable collection of KeyValues that are guaranteed to be sorted and deduplicated by key.
Authors
Jon Schneider, Maciej Walkowiak, Phillip Webb, Johnny Lim
Since
1.10.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final KeyValues
private final KeyValue[]
private int

Constructor Summary

AccessConstructor and Description
private
KeyValues(KeyValue[] keyValues)

Method Summary

Modifier and TypeMethod and Description
public KeyValues

Returns:

a new KeyValues instance
and
(String
the key to add
key
,
String
the value to add
value
)

Return a new KeyValues instance by merging this collection and the specified key/value pair.

public KeyValues

Returns:

a new KeyValues instance
and
(String...
the key/value pairs to add, elements mustn't be null
keyValues
)

Return a new KeyValues instance by merging this collection and the specified key/value pairs.

public KeyValues

Returns:

a new KeyValues instance
and
(KeyValue...
the key values to add, elements mustn't be null
keyValues
)

Return a new KeyValues instance by merging this collection and the specified key values.

public <E> KeyValues

Returns:

a new KeyValues instance
and
(Iterable<E>
the source elements
elements
,
Function<E, String>
function to extract the key from the element
keyExtractor
,
Function<E, String>
function to extract the value from the element
valueExtractor
)

Return a new KeyValues instance by merging this collection and the key values extracted from the given elements.

public KeyValues

Returns:

a new KeyValues instance
and
(Iterable<? extends KeyValue>
the key values to add, elements mustn't be null
keyValues
)

Return a new KeyValues instance by merging this collection and the specified key values.

private static boolean
public static KeyValues

Returns:

the merged key values
concat
(Iterable<? extends KeyValue>
the first set of key values, elements mustn't be null
keyValues
,
Iterable<? extends KeyValue>
the second set of key values, elements mustn't be null
otherKeyValues
)

Return a new KeyValues instance by concatenating the specified collections of key values.

public static KeyValues

Returns:

the merged key values
concat
(Iterable<? extends KeyValue>
the first set of key values, elements mustn't be null
keyValues
,
String...
the additional key/value pairs to add, elements mustn't be null
otherKeyValues
)

Return a new KeyValues instance by concatenating the specified key values and key/value pairs.

private void
public static KeyValues

Returns:

an empty KeyValues instance
empty
()

Return a KeyValues instance that contains no elements.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public Iterator<KeyValue>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.
private boolean
public static <E> KeyValues

Returns:

a new KeyValues instance
of
(Iterable<E>
the source elements
elements
,
Function<E, String>
function to extract the key from the element
keyExtractor
,
Function<E, String>
function to extract the value from the element
valueExtractor
)

Return a new KeyValues instance containing key values extracted from the given elements.

public static KeyValues

Returns:

a new KeyValues instance
of
(Iterable<? extends KeyValue>
the key values to add, elements mustn't be null
keyValues
)

Return a new KeyValues instance containing key values constructed from the specified source key values.

public static KeyValues

Returns:

a new KeyValues instance
of
(String
the key to add
key
,
String
the value to add
value
)

Return a new KeyValues instance containing key value constructed from the specified key/value pair.

public static KeyValues

Returns:

a new KeyValues instance
of
(String...
the key/value pairs to add, elements mustn't be null
keyValues
)

Return a new KeyValues instance containing key values constructed from the specified key/value pairs.

public static KeyValues

Returns:

a new KeyValues instance
of
(KeyValue...
the key values to add, elements mustn't be null
keyValues
)

Return a new KeyValues instance containing key values constructed from the specified key values.

public Spliterator<KeyValue>
spliterator()

Overrides default java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.
public Stream<KeyValue>

Returns:

a key value stream
stream
()

Return a stream of the contained key values.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTYback to summary
private static final KeyValues EMPTY
keyValuesback to summary
private final KeyValue[] keyValues
lastback to summary
private int last

Constructor Detail

KeyValuesback to summary
private KeyValues(KeyValue[] keyValues)

Method Detail

andback to summary
public KeyValues and(String key, String value)

Return a new KeyValues instance by merging this collection and the specified key/value pair.

Parameters
key:String

the key to add

value:String

the value to add

Returns:KeyValues

a new KeyValues instance

andback to summary
public KeyValues and(String... keyValues)

Return a new KeyValues instance by merging this collection and the specified key/value pairs.

Parameters
keyValues:String[]

the key/value pairs to add, elements mustn't be null

Returns:KeyValues

a new KeyValues instance

andback to summary
public KeyValues and(KeyValue... keyValues)

Return a new KeyValues instance by merging this collection and the specified key values.

Parameters
keyValues:KeyValue[]

the key values to add, elements mustn't be null

Returns:KeyValues

a new KeyValues instance

andback to summary
public <E> KeyValues and(Iterable<E> elements, Function<E, String> keyExtractor, Function<E, String> valueExtractor)

Return a new KeyValues instance by merging this collection and the key values extracted from the given elements.

Parameters
elements:Iterable<E>

the source elements

keyExtractor:Function<E, String>

function to extract the key from the element

valueExtractor:Function<E, String>

function to extract the value from the element

Returns:KeyValues

a new KeyValues instance

andback to summary
public KeyValues and(Iterable<? extends KeyValue> keyValues)

Return a new KeyValues instance by merging this collection and the specified key values.

Parameters
keyValues:Iterable<? extends KeyValue>

the key values to add, elements mustn't be null

Returns:KeyValues

a new KeyValues instance

blankVarargsback to summary
private static boolean blankVarargs(Object[] args)
concatback to summary
public static KeyValues concat(Iterable<? extends KeyValue> keyValues, Iterable<? extends KeyValue> otherKeyValues)

Return a new KeyValues instance by concatenating the specified collections of key values.

Parameters
keyValues:Iterable<? extends KeyValue>

the first set of key values, elements mustn't be null

otherKeyValues:Iterable<? extends KeyValue>

the second set of key values, elements mustn't be null

Returns:KeyValues

the merged key values

concatback to summary
public static KeyValues concat(Iterable<? extends KeyValue> keyValues, String... otherKeyValues)

Return a new KeyValues instance by concatenating the specified key values and key/value pairs.

Parameters
keyValues:Iterable<? extends KeyValue>

the first set of key values, elements mustn't be null

otherKeyValues:String[]

the additional key/value pairs to add, elements mustn't be null

Returns:KeyValues

the merged key values

dedupback to summary
private void dedup()
emptyback to summary
public static KeyValues empty()

Return a KeyValues instance that contains no elements.

Returns:KeyValues

an empty KeyValues instance

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
iteratorback to summary
public Iterator<KeyValue> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<KeyValue>

an Iterator.

Annotations
@Override
keyValuesEqualback to summary
private boolean keyValuesEqual(KeyValues obj)
ofback to summary
public static <E> KeyValues of(Iterable<E> elements, Function<E, String> keyExtractor, Function<E, String> valueExtractor)

Return a new KeyValues instance containing key values extracted from the given elements.

Parameters
elements:Iterable<E>

the source elements

keyExtractor:Function<E, String>

function to extract the key from the element

valueExtractor:Function<E, String>

function to extract the value from the element

Returns:KeyValues

a new KeyValues instance

ofback to summary
public static KeyValues of(Iterable<? extends KeyValue> keyValues)

Return a new KeyValues instance containing key values constructed from the specified source key values.

Parameters
keyValues:Iterable<? extends KeyValue>

the key values to add, elements mustn't be null

Returns:KeyValues

a new KeyValues instance

ofback to summary
public static KeyValues of(String key, String value)

Return a new KeyValues instance containing key value constructed from the specified key/value pair.

Parameters
key:String

the key to add

value:String

the value to add

Returns:KeyValues

a new KeyValues instance

ofback to summary
public static KeyValues of(String... keyValues)

Return a new KeyValues instance containing key values constructed from the specified key/value pairs.

Parameters
keyValues:String[]

the key/value pairs to add, elements mustn't be null

Returns:KeyValues

a new KeyValues instance

ofback to summary
public static KeyValues of(KeyValue... keyValues)

Return a new KeyValues instance containing key values constructed from the specified key values.

Parameters
keyValues:KeyValue[]

the key values to add, elements mustn't be null

Returns:KeyValues

a new KeyValues instance

spliteratorback to summary
public Spliterator<KeyValue> spliterator()

Overrides default java.lang.Iterable.spliterator.

Doc from java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

Returns:Spliterator<KeyValue>

a Spliterator over the elements described by this Iterable.

Annotations
@Override
streamback to summary
public Stream<KeyValue> stream()

Return a stream of the contained key values.

Returns:Stream<KeyValue>

a key value stream

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
io.micrometer.common back to summary

private Class KeyValues.ArrayIterator

extends Object
implements Iterator<KeyValue>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public KeyValue
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentIndexback to summary
private int currentIndex

Constructor Detail

ArrayIteratorback to summary
private ArrayIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public KeyValue next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:KeyValue

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override