public final class Utils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <K,V> V |
computeIfAbsent(java.util.concurrent.ConcurrentMap<K,V> map,
K k,
java.util.function.Function<K,V> f)
This method should be used instead of the
ConcurrentMap.computeIfAbsent(Object, Function) call to minimize
thread contention. |
static java.lang.Iterable<Measurement> |
filter(java.lang.Iterable<Measurement> ms,
java.util.function.Predicate<Measurement> p)
Returns a new iterable restricted to measurements that match the predicate.
|
static java.lang.Iterable<Measurement> |
filter(java.lang.Iterable<Measurement> ms,
java.lang.String k,
java.lang.String v)
Returns a new iterable restricted to measurements that match the predicate.
|
static java.lang.Iterable<Measurement> |
filter(java.lang.Iterable<Measurement> ms,
Tag t)
Returns a new iterable restricted to measurements that match the predicate.
|
static Measurement |
first(java.lang.Iterable<Measurement> ms,
java.util.function.Predicate<Measurement> p)
Returns the first measurement that matches the predicate.
|
static Measurement |
first(java.lang.Iterable<Measurement> ms,
java.lang.String k,
java.lang.String v)
Returns the first measurement with a given tag value.
|
static Measurement |
first(java.lang.Iterable<Measurement> ms,
Tag t)
Returns the first measurement with a given tag value.
|
static java.lang.String |
getTagValue(Id id,
java.lang.String k)
Returns the value associated with with a given key or null if no such key is present in the
set of tags.
|
static java.lang.String |
getTagValue(java.lang.Iterable<Tag> tags,
java.lang.String k)
Returns the value associated with with a given key or null if no such key is present in the
set of tags.
|
static Id |
normalize(Id id)
Returns a new id with the tag list sorted by key and with no duplicate keys.
|
static void |
propagateTypeError(Registry registry,
Id id,
java.lang.Class<?> desiredClass,
java.lang.Class<?> actualClass)
Propagate a type error exception.
|
static <T> int |
size(java.lang.Iterable<T> iter)
Returns the size of an iterable.
|
static <T> java.util.List<T> |
toList(java.lang.Iterable<T> iter)
Returns a list with a copy of the data from the iterable.
|
static <T> java.util.List<T> |
toList(java.util.Iterator<T> iter)
Returns a list with the data from the iterator.
|
public static Id normalize(Id id)
public static java.lang.String getTagValue(Id id, java.lang.String k)
id
- Identifier with a set of tags to search.k
- Key to search for.public static java.lang.String getTagValue(java.lang.Iterable<Tag> tags, java.lang.String k)
tags
- Set of tags to search.k
- Key to search for.public static Measurement first(java.lang.Iterable<Measurement> ms, Tag t)
ms
- A set of measurements.t
- The key and value to search for.public static Measurement first(java.lang.Iterable<Measurement> ms, java.lang.String k, java.lang.String v)
ms
- A set of measurements.k
- Key to search for.v
- Value that should be associated with k on the ids.public static Measurement first(java.lang.Iterable<Measurement> ms, java.util.function.Predicate<Measurement> p)
ms
- A set of measurements.p
- Predicate to use for selecting values.public static java.lang.Iterable<Measurement> filter(java.lang.Iterable<Measurement> ms, Tag t)
ms
- A set of measurements.t
- The key and value to search for.public static java.lang.Iterable<Measurement> filter(java.lang.Iterable<Measurement> ms, java.lang.String k, java.lang.String v)
ms
- A set of measurements.k
- Key to search for.v
- Value that should be associated with k on the ids.public static java.lang.Iterable<Measurement> filter(java.lang.Iterable<Measurement> ms, java.util.function.Predicate<Measurement> p)
ms
- A set of measurements.p
- Predicate to use for selecting values.public static <T> java.util.List<T> toList(java.lang.Iterable<T> iter)
public static <T> java.util.List<T> toList(java.util.Iterator<T> iter)
public static <T> int size(java.lang.Iterable<T> iter)
public static <K,V> V computeIfAbsent(java.util.concurrent.ConcurrentMap<K,V> map, K k, java.util.function.Function<K,V> f)
ConcurrentMap.computeIfAbsent(Object, Function)
call to minimize
thread contention. This method does not require locking for the common case
where the key exists, but potentially performs additional computation when
absent.