blob: 38066373b282f93df292574d5382595283c97d8c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package com.yahoo.vespa.tenant.cd.metrics;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.toUnmodifiableMap;
/**
* Used to easily generate points for a pre-defined space.
*
* @author jonmv
*/
public class Space {
private final List<String> dimensions;
private Space(List<String> dimensions) {
this.dimensions = dimensions;
}
/** Creates a new space with the given named dimensions, in order. */
public static Space of(List<String> dimensions) {
if (Set.copyOf(dimensions).size() != dimensions.size())
throw new IllegalArgumentException("Duplicated dimension names in '" + dimensions + "'.");
return new Space(List.copyOf(dimensions));
}
/** Returns a point in this space, with the given values along each dimensions, in order. */
public Map<String, ?> at(List<?> values) {
if (dimensions.size() != values.size())
throw new IllegalArgumentException("This space has " + dimensions.size() + " dimensions, but " + values.size() + " were given.");
return IntStream.range(0, dimensions.size()).boxed().collect(toUnmodifiableMap(dimensions::get, values::get));
}
/** Returns a point in this space, with the given values along each dimensions, in order. */
public Map<String, ?> at(Object... values) {
return at(List.of(values));
}
}
|