<commit_before>package eu.cloudscaleproject.env.toolchain.explorer;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.e4.core.contexts.IEclipseContext;

import eu.cloudscaleproject.env.toolchain.resources.IExplorerContentRetriever;
import eu.cloudscaleproject.env.toolchain.resources.ProjectResourceRegistry;
import eu.cloudscaleproject.env.toolchain.resources.ResourceProvider;
import eu.cloudscaleproject.env.toolchain.resources.ResourceRegistry;
import eu.cloudscaleproject.env.toolchain.resources.types.IConfigAlternative;
import eu.cloudscaleproject.env.toolchain.resources.types.IEditorInputResource;
import eu.cloudscaleproject.env.toolchain.resources.types.IResultAlternative;

public class ExplorerAlternativesRetriever implements IExplorerContentRetriever{

	private final PropertyChangeListener resourceRegistryListener = new PropertyChangeListener() {
		
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			
			if(ProjectResourceRegistry.PROP_RESOURCE_PROVIDER_ADDED.equals(evt.getPropertyName())){
				ResourceProvider rp = (ResourceProvider)evt.getNewValue();
				if(rp.getID().equals(resourceProviderID)){
					registerResourceProvider(rp);
				}
				
			}
			if(ProjectResourceRegistry.PROP_RESOURCE_PROVIDER_REMOVED.equals(evt.getPropertyName())){
				ResourceProvider rp = (ResourceProvider)evt.getOldValue();
				if(rp.getID().equals(resourceProviderID)){
					unregisterResourceProvider(resourceProvider);
				}
			}
			
			pcs.firePropertyChange(PROP_CHILDREN_CHANGED, null, this);
		}
	};
	
	private final PropertyChangeListener resourceProviderListener = new PropertyChangeListener() {
		
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			pcs.firePropertyChange(PROP_CHILDREN_CHANGED, null, this);
		}
	};

	private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
	
	private IProject project;
	private String resourceProviderID;
	
	private IEclipseContext context;
	
	private ProjectResourceRegistry projectResourceRegistry;
	private ResourceProvider resourceProvider;
	
	public void initialize(String nodeID, IEclipseContext context){
		
		this.project = context.get(IProject.class);
		this.resourceProviderID = nodeID;
		
		this.context = context;
		
		this.projectResourceRegistry = ResourceRegistry.getInstance().getProjectResourceRegistry(project);
		this.projectResourceRegistry.addPropertyChangeListener(resourceRegistryListener);
		
		ResourceProvider rp = ResourceRegistry.getInstance().getResourceProvider(project, nodeID);
		if(rp != null){
			registerResourceProvider(rp);
		}
		
	}
	
	private void registerResourceProvider(ResourceProvider rp){
		
		if(rp == null){
			return;
		}
		
		this.resourceProvider = rp;
		
		rp.addListener(resourceProviderListener);
		this.context.set(ResourceProvider.class, rp);
	}
	
	private void unregisterResourceProvider(ResourceProvider rp){

		if(rp == null){
			return;
		}
		
		this.resourceProvider = null;

		rp.removeListener(resourceProviderListener);
		this.context.set(ResourceProvider.class, null);
	}
	
	@Override
	public List<Object> getChildren() {
		
		IEditorInputResource parentEir = context.get(IEditorInputResource.class);
		
		List<Object> out = new ArrayList<Object>();		
			
		for(IEditorInputResource eir : resourceProvider.getResources()){
			
			if(eir instanceof IConfigAlternative){
				IConfigAlternative ca = (IConfigAlternative)eir;
				if(ca.getInputAlternative() == parentEir){
					out.add(eir);
				}
				continue;
			}
			
			if(eir instanceof IResultAlternative){
				IResultAlternative ra = (IResultAlternative)eir;
				if(ra.getInputAlternative() == parentEir || ra.getConfigAlternative() == parentEir){<commit_msg>Null pointer exception fixed<commit_after>package eu.cloudscaleproject.env.toolchain.explorer;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.e4.core.contexts.IEclipseContext;

import eu.cloudscaleproject.env.toolchain.resources.IExplorerContentRetriever;
import eu.cloudscaleproject.env.toolchain.resources.ProjectResourceRegistry;
import eu.cloudscaleproject.env.toolchain.resources.ResourceProvider;
import eu.cloudscaleproject.env.toolchain.resources.ResourceRegistry;
import eu.cloudscaleproject.env.toolchain.resources.types.IConfigAlternative;
import eu.cloudscaleproject.env.toolchain.resources.types.IEditorInputResource;
import eu.cloudscaleproject.env.toolchain.resources.types.IResultAlternative;

public class ExplorerAlternativesRetriever implements IExplorerContentRetriever{

	private final PropertyChangeListener resourceRegistryListener = new PropertyChangeListener() {
		
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			
			if(ProjectResourceRegistry.PROP_RESOURCE_PROVIDER_ADDED.equals(evt.getPropertyName())){
				ResourceProvider rp = (ResourceProvider)evt.getNewValue();
				if(rp.getID().equals(resourceProviderID)){
					registerResourceProvider(rp);
				}
				
			}
			if(ProjectResourceRegistry.PROP_RESOURCE_PROVIDER_REMOVED.equals(evt.getPropertyName())){
				ResourceProvider rp = (ResourceProvider)evt.getOldValue();
				if(rp.getID().equals(resourceProviderID)){
					unregisterResourceProvider(resourceProvider);
				}
			}
			
			pcs.firePropertyChange(PROP_CHILDREN_CHANGED, null, this);
		}
	};
	
	private final PropertyChangeListener resourceProviderListener = new PropertyChangeListener() {
		
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			pcs.firePropertyChange(PROP_CHILDREN_CHANGED, null, this);
		}
	};

	private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
	
	private IProject project;
	private String resourceProviderID;
	
	private IEclipseContext context;
	
	private ProjectResourceRegistry projectResourceRegistry;
	private ResourceProvider resourceProvider;
	
	public void initialize(String nodeID, IEclipseContext context){
		
		this.project = context.get(IProject.class);
		this.resourceProviderID = nodeID;
		
		this.context = context;
		
		this.projectResourceRegistry = ResourceRegistry.getInstance().getProjectResourceRegistry(project);
		this.projectResourceRegistry.addPropertyChangeListener(resourceRegistryListener);
		
		ResourceProvider rp = ResourceRegistry.getInstance().getResourceProvider(project, nodeID);
		if(rp != null){
			registerResourceProvider(rp);
		}
		
	}
	
	private void registerResourceProvider(ResourceProvider rp){
		
		if(rp == null){
			return;
		}
		
		this.resourceProvider = rp;
		
		rp.addListener(resourceProviderListener);
		this.context.set(ResourceProvider.class, rp);
	}
	
	private void unregisterResourceProvider(ResourceProvider rp){

		if(rp == null){
			return;
		}
		
		this.resourceProvider = null;

		rp.removeListener(resourceProviderListener);
		this.context.set(ResourceProvider.class, null);
	}
	
	@Override
	public List<Object> getChildren() {
		
		IEditorInputResource parentEir = context.get(IEditorInputResource.class);
		
		List<Object> out = new ArrayList<Object>();		

		if(resourceProvider == null){
			return out;
		}
			
		for(IEditorInputResource eir : resourceProvider.getResources()){
			
			if(eir instanceof IConfigAlternative){
				IConfigAlternative ca = (IConfigAlternative)eir;
				if(ca.getInputAlternative() == parentEir){
					out.add(eir);
				}
				continue;
			}
			
			if(eir instanceof IResultAlternative){
				IResultAlternative ra = (IResultAlternative)eir;
				if(ra.getInputAlternative() == parentEir || ra.getConfigAlternative() == parentEir){
{'fraction_non_alphanumeric': 0.09209683617266555, 'fraction_numerical': 0.0002561803509670808, 'mean_word_length': 5.572390572390573, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7397920', 'n_tokens_mistral': 2566, 'n_tokens_neox': 2194, 'n_words': 358}