All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.groupon.lex.metrics.resolver.NameBoundResolver Maven / Gradle / Ivy

The newest version!
package com.groupon.lex.metrics.resolver;

import com.groupon.lex.metrics.MetricValue;
import com.groupon.lex.metrics.lib.Any2;
import com.groupon.lex.metrics.lib.Any3;
import com.groupon.lex.metrics.lib.SimpleMapEntry;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public interface NameBoundResolver extends AutoCloseable {
    public static final NameBoundResolver EMPTY = new NameBoundResolver() {
        @Override
        public Stream resolve() {
            return Stream.of(NamedResolverMap.EMPTY);
        }

        @Override
        public Stream> getKeys() {
            return Stream.empty();
        }

        @Override
        public boolean isEmpty() {
            return true;
        }

        @Override
        public String configString() {
            return "";
        }

        @Override
        public void close() {
        }
    };

    public Stream resolve() throws Exception;

    public Stream> getKeys();

    public boolean isEmpty();

    public String configString();

    /**
     * @return a tag map from a resolved map.
     */
    @Deprecated
    public static Map tagMap(Map, Any3> nrMap) {
        return nrMap.entrySet().stream()
                .map(entry -> {
                    final MetricValue tagValue = entry.getValue().mapCombine(MetricValue::fromBoolean, MetricValue::fromIntValue, MetricValue::fromStrValue);
                    return entry.getKey().getRight()
                            .map(tagName -> SimpleMapEntry.create(tagName, tagValue));
                })
                .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }

    /**
     * @return an index-to-string map from a resolved map.
     */
    @Deprecated
    public static Map indexToStringMap(Map, Any3> nrMap) {
        return nrMap.entrySet().stream()
                .map(entry -> {
                    final String tagValue = entry.getValue().mapCombine(String::valueOf, String::valueOf, String::valueOf);
                    return entry.getKey().getLeft()
                            .map(tagName -> SimpleMapEntry.create(tagName, tagValue));
                })
                .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy