<commit_before>package ch.elexis.core.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.slf4j.LoggerFactory;

import ch.elexis.core.model.ICodeElement;

@Component
public class CodeElementService implements ICodeElementService {
	
	private HashMap<String, ICodeElementServiceContribution> contributions = new HashMap<>();
	
	@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
	public void setCodeElementServiceContribution(ICodeElementServiceContribution contribution){
		ICodeElementServiceContribution previous =
			contributions.put(contribution.getSystem(), contribution);
		if (previous != null) {
			LoggerFactory.getLogger(getClass())
				.warn("Possible ICodeElementServiceContribution collision previous [" + previous
					+ "] new [" + contribution + "]");
		}
	}
	
	public void unsetCodeElementServiceContribution(ICodeElementServiceContribution store){
		contributions.remove(store.getSystem());
	}
	
	@Override
	public Optional<ICodeElement> loadFromString(String system, String code,
		Map<Object, Object> context){
		ICodeElementServiceContribution contribution = contributions.get(system);
		if (contribution != null) {
			return contribution.loadFromCode(code, context);
		} else {
			LoggerFactory.getLogger(getClass())
				.warn("No ICodeElementServiceContribution for system [" + system + "] code [" + code
					+ "]");
		}
		return Optional.empty();
	}
	
	@Override
	public List<ICodeElementServiceContribution> getContributionsByTyp(CodeElementTyp typ){
		return contributions.values().stream().filter(contribution -> contribution.getTyp() == typ)
			.collect(Collectors.toList());
	}
	<commit_msg>[14501] CodeElementService do pass empty map, not null<commit_after>package ch.elexis.core.services;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.slf4j.LoggerFactory;

import ch.elexis.core.model.ICodeElement;

@Component
public class CodeElementService implements ICodeElementService {
	
	private HashMap<String, ICodeElementServiceContribution> contributions = new HashMap<>();
	
	@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
	public void setCodeElementServiceContribution(ICodeElementServiceContribution contribution){
		ICodeElementServiceContribution previous =
			contributions.put(contribution.getSystem(), contribution);
		if (previous != null) {
			LoggerFactory.getLogger(getClass())
				.warn("Possible ICodeElementServiceContribution collision previous [" + previous
					+ "] new [" + contribution + "]");
		}
	}
	
	public void unsetCodeElementServiceContribution(ICodeElementServiceContribution store){
		contributions.remove(store.getSystem());
	}
	
	@Override
	public Optional<ICodeElement> loadFromString(String system, String code,
		Map<Object, Object> context){
		ICodeElementServiceContribution contribution = contributions.get(system);
		if (contribution != null) {
			if (context == null) {
				context = Collections.emptyMap();
			}
			return contribution.loadFromCode(code, context);
		} else {
			LoggerFactory.getLogger(getClass())
				.warn("No ICodeElementServiceContribution for system [" + system + "] code [" + code
					+ "]");
		}
		return Optional.empty();
	}
	
	@Override
	public List<ICodeElementServiceContribution> getContributionsByTyp(CodeElementTyp typ){
		return contributions.values().stream().filter(contribution -> contribution.getTyp() == typ)
			.collect(Collectors.toList());
	}
	
{'fraction_non_alphanumeric': 0.10546697038724373, 'fraction_numerical': 0.0015945330296127562, 'mean_word_length': 6.105177993527508, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '6892964', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1198, 'n_words': 230}