<commit_before>/**
 * Copyright (c) 2013 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.simulation.core.language;

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

import org.yakindu.sct.model.sgraph.Statechart;

import com.google.inject.Module;
import com.google.inject.util.Modules;

/**
 * Handles a set of language providers and provides language dependencies resolving features.
 * 
 * @author terfloth - Initial contribution
 *
 */
public class SCLanguageProviders {

	protected SCLanguages languages = new SCLanguages();
	protected Map<ISCLanguage, ISCLanguageProvider> providerMap = new HashMap<ISCLanguage, ISCLanguageProvider>();
	
	public void addLanguageProvider(ISCLanguageProvider provider) {
		if (! languages.contains(provider.getLanguage()) ) {
			languages.addLanguage(provider.getLanguage());
			providerMap.put(provider.getLanguage(), provider);
		}
	}
	
	public List<ISCLanguageProvider> getLanguageProviders() {
		return new ArrayList<ISCLanguageProvider>(providerMap.values());
	}
	
	
	public ISCLanguageProvider getProviderFor(Statechart sc) {
		for (Iterator<ISCLanguageProvider> iterator = providerMap.values().iterator(); iterator.hasNext();) {
			ISCLanguageProvider provider = (ISCLanguageProvider) iterator.next();
			if (provider.isInstanceOfLanguage(sc)) return provider;	
		}		
		return null;
	}
	
	
	public Module getSimulationModuleFor(Statechart sc){
		return getSimulationModuleForLanguage(getProviderFor(sc).getLanguage());
	}
	
	
	public Module getSimulationModuleForLanguage(ISCLanguage language) {
		ISCLanguageProvider provider = providerMap.get(language);
		Module module = provider.getSimulationModule();
		
		ISCLanguage baseLanguage = languages.getBaseLanguage(language);
		if (baseLanguage != null) {
			Module baseModule = getSimulationModuleForLanguage(baseLanguage);
			return Modules.override(baseModule).with(module);
		}
		return module;
	}
}<commit_msg>SCLanguageProviders class now looksup language providers by language id instead of language instance.<commit_after>/**
 * Copyright (c) 2013 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.simulation.core.language;

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

import org.yakindu.sct.model.sgraph.Statechart;

import com.google.inject.Module;
import com.google.inject.util.Modules;

/**
 * Handles a set of language providers and provides language dependencies resolving features.
 * 
 * @author terfloth - Initial contribution
 *
 */
public class SCLanguageProviders {

	protected SCLanguages languages = new SCLanguages();
	protected Map<String, ISCLanguageProvider> providerMap = new HashMap<String, ISCLanguageProvider>();
	
	public void addLanguageProvider(ISCLanguageProvider provider) {
		if (! languages.contains(provider.getLanguage()) ) {
			languages.addLanguage(provider.getLanguage());
			providerMap.put(provider.getLanguage().getId(), provider);
		}
	}
	
	public List<ISCLanguageProvider> getLanguageProviders() {
		return new ArrayList<ISCLanguageProvider>(providerMap.values());
	}
	
	
	public ISCLanguageProvider getProviderFor(Statechart sc) {
		for (Iterator<ISCLanguageProvider> iterator = providerMap.values().iterator(); iterator.hasNext();) {
			ISCLanguageProvider provider = (ISCLanguageProvider) iterator.next();
			if (provider.isInstanceOfLanguage(sc)) return provider;	
		}		
		return null;
	}
	
	
	public Module getSimulationModuleFor(Statechart sc){
		return getSimulationModuleForLanguage(getProviderFor(sc).getLanguage());
	}
	
	
	public Module getSimulationModuleForLanguage(ISCLanguage language) {
		ISCLanguageProvider provider = providerMap.get(language.getId());
		Module module = provider.getSimulationModule();
		
		ISCLanguage baseLanguage = languages.getBaseLanguage(language);
		if (baseLanguage != null) {
			Module baseModule = getSimulationModuleForLanguage(baseLanguage);
			return Modules.override(baseModule).with(module);
		}
		return module;
	}
}
{'fraction_non_alphanumeric': 0.09671302149178256, 'fraction_numerical': 0.00337126000842815, 'mean_word_length': 5.346256684491979, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4498251', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1304, 'n_words': 330}