summaryrefslogtreecommitdiffstats
path: root/metrics/src/main/java/com/yahoo/metrics/ConsumerSpec.java
blob: f97d8fd85ee04efff500ed6fc2eab4de17ae3b02 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.metrics;

import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * Spec saved from config. If metricSetChildren has content, metric pointed
 * to is a metric set.
 */
class ConsumerSpec {
    Set<String> includedMetrics = new HashSet<String>();

    public boolean contains(Metric m) {
        return includedMetrics.contains(m.getPath());
    }

    public void register(String path) {
        StringTokenizer tokenizer = new StringTokenizer(path, ".");

        String total = "";

        while (tokenizer.hasMoreTokens()) {
            if (!total.isEmpty()) {
                total += ".";
            }
            total += tokenizer.nextToken();
            includedMetrics.add(total);
        }
    }
}