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

com.fnklabs.draenei.analytics.SimilarityAlgorithmFactory Maven / Gradle / Ivy

There is a newer version: 0.8.3
Show newest version
package com.fnklabs.draenei.analytics;

import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Factory for retrieving similarity algorithm
 */
final class SimilarityAlgorithmFactory {

    /**
     * Similarity algorithms map
     */
    private final Map algorithms = new HashMap<>();

    public SimilarityAlgorithmFactory(List similarityAlgorithmList) {
        similarityAlgorithmList.forEach(algorithm -> {
            getAlgorithms().put(algorithm.getClass().getName(), algorithm);
        });
    }

    /**
     * Get similarity algorithm
     *
     * @param algorithm Similarity algorithm
     *
     * @return SimilarityAlgorithm instance
     */
    @NotNull
    public SimilarityAlgorithm get(@NotNull String algorithm) {
        if (!getAlgorithms().containsKey(algorithm)) {
            LoggerFactory.getLogger(SimilarityAlgorithmFactory.class).warn("Requested unknown algorithm: {} available algorithms: {}", algorithm, getAlgorithms().keySet());
            throw new UnknownAlgorithm(algorithm);
        }

        return getAlgorithms().get(algorithm);
    }

    private Map getAlgorithms() {
        return algorithms;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy