<commit_before>package br.com.caelum.vraptor.ioc.cdi;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.CDI;
import javax.inject.Inject;

import br.com.caelum.vraptor.cache.LRU;
import br.com.caelum.vraptor.cache.VRaptorCache;
import br.com.caelum.vraptor.ioc.Container;

@ApplicationScoped
@SuppressWarnings("rawtypes")
public class CDIBasedContainer implements Container {
	
	private VRaptorCache<String,Instance> cache;

	@Deprecated
	public CDIBasedContainer() {
	}
	
	@Inject
	public CDIBasedContainer(@LRU(capacity=1000) VRaptorCache<String, Instance> cache) {
		super();
		this.cache = cache;
	}

	@Override
	public <T> T instanceFor(Class<T> type) {
		return selectFromContainer(type).get();
	}

	@Override
	public <T> boolean canProvide(Class<T> type) {
		return !selectFromContainer(type).isUnsatisfied();
	}

	private <T> Instance<T> selectFromContainer(Class<T> type) {
		String className = type.getCanonicalName();
		if(cache.get(className)==null){
			Instance<T> instance = CDI.current().select(type);
			cache.put(className,instance);
		}
		return cache.get(className);
	}
}<commit_msg>cache using type as key instead of string<commit_after>package br.com.caelum.vraptor.ioc.cdi;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.CDI;
import javax.inject.Inject;

import br.com.caelum.vraptor.cache.LRU;
import br.com.caelum.vraptor.cache.VRaptorCache;
import br.com.caelum.vraptor.ioc.Container;

@ApplicationScoped
@SuppressWarnings("rawtypes")
public class CDIBasedContainer implements Container {
	
	private VRaptorCache<Class<?>,Instance> cache;

	@Deprecated
	public CDIBasedContainer() {
	}
	
	@Inject
	public CDIBasedContainer(@LRU(capacity=1000) VRaptorCache<Class<?>, Instance> cache) {
		super();
		this.cache = cache;
	}

	@Override
	public <T> T instanceFor(Class<T> type) {
		return selectFromContainer(type).get();
	}

	@Override
	public <T> boolean canProvide(Class<T> type) {
		return !selectFromContainer(type).isUnsatisfied();
	}

	private <T> Instance<T> selectFromContainer(Class<T> type) {
		if(cache.get(type)==null){
			Instance<T> instance = CDI.current().select(type);
			cache.putIfAbsent(type,instance);
		}
		return cache.get(type);
	}
}
{'fraction_non_alphanumeric': 0.1305091998288404, 'fraction_numerical': 0.0034231921266581087, 'mean_word_length': 5.737752161383285, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6964130', 'n_tokens_mistral': 852, 'n_tokens_neox': 815, 'n_words': 142}