<commit_before>package com.skcraft.plume.common.util.service;

import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import com.google.inject.Singleton;

import java.util.concurrent.ConcurrentMap;

import static com.google.common.base.Preconditions.checkNotNull;

@Singleton
public class ServiceLocator {

    private final ConcurrentMap<Class<?>, Object> providers = Maps.newConcurrentMap();

    @SuppressWarnings("unchecked")
    public <T> void register(Class<?> service, T implementation) {
        checkNotNull(service, "service");
        checkNotNull(implementation, "implementation");
        T previous;
        if ((previous = (T) providers.putIfAbsent(service, implementation)) != null) {
            throw new IllegalArgumentException("There is already an implementation (" + previous.getClass().getName() + ") for " + service.getName());
        }
    }

    @SuppressWarnings("unchecked")
    public <T> T provide(Class<T> service) throws NoProviderExistsException {
        T provider = (T) providers.get(service);
        if (provider != null) {
            return provider;
        } else {
            throw new NoProviderExistsException("No provider is known for " + service);
        }
    }

    @SuppressWarnings("unchecked")
    public <T> Optional<T> get(Class<T> service) {
        T provider = (T) providers.get(service);
        if (provider != null) {
            return Optional.fromNullable(provider);
        } else {
            return Optional.absent();<commit_msg>Fix ServiceLocator.register() not utilizing correct generic type.<commit_after>package com.skcraft.plume.common.util.service;

import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import com.google.inject.Singleton;

import java.util.concurrent.ConcurrentMap;

import static com.google.common.base.Preconditions.checkNotNull;

@Singleton
public class ServiceLocator {

    private final ConcurrentMap<Class<?>, Object> providers = Maps.newConcurrentMap();

    @SuppressWarnings("unchecked")
    public <T> void register(Class<T> service, T implementation) {
        checkNotNull(service, "service");
        checkNotNull(implementation, "implementation");
        T previous;
        if ((previous = (T) providers.putIfAbsent(service, implementation)) != null) {
            throw new IllegalArgumentException("There is already an implementation (" + previous.getClass().getName() + ") for " + service.getName());
        }
    }

    @SuppressWarnings("unchecked")
    public <T> T provide(Class<T> service) throws NoProviderExistsException {
        T provider = (T) providers.get(service);
        if (provider != null) {
            return provider;
        } else {
            throw new NoProviderExistsException("No provider is known for " + service);
        }
    }

    @SuppressWarnings("unchecked")
    public <T> Optional<T> get(Class<T> service) {
        T provider = (T) providers.get(service);
        if (provider != null) {
            return Optional.fromNullable(provider);
        } else {
            return Optional.absent();
{'fraction_non_alphanumeric': 0.11774193548387096, 'fraction_numerical': 0.0, 'mean_word_length': 3.2654745529573592, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1794372', 'n_tokens_mistral': 820, 'n_tokens_neox': 820, 'n_words': 199}