<commit_before>package org.lamport.tla.toolbox.tool.tlc.output.internal;

import java.util.Vector;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.lamport.tla.toolbox.tool.tlc.TLCActivator;
import org.lamport.tla.toolbox.tool.tlc.output.IProcessOutputSink;

/**
 * A listener broadcasting the stream appending to extensions 
 * @author <NAME>
 * @version $Id$
 */
public class BroadcastStreamListener implements IStreamListener
{
    private IProcessOutputSink[] listeners = null;

    /**
     * 
     * @param streamName
     * @param kind, see constants {@link IProcessOutputSink#TYPE_DEBUG}, {@link IProcessOutputSink#TYPE_ERROR}, {@link IProcessOutputSink#TYPE_OUT}
     */
    public BroadcastStreamListener(String streamName, int kind)
    {
        this.listeners = getRegisteredStreamManagers(streamName, kind);
    }

    /* (non-Javadoc)
     * @see org.eclipse.debug.core.IStreamListener#streamAppended(java.lang.String, org.eclipse.debug.core.model.IStreamMonitor)
     */
    public synchronized void streamAppended(String text, IStreamMonitor monitor)
    {
        // broadcast the message
        for (int i = 0; i < listeners.length; i++)
        {
            if (listeners[i] != null)
            {
                try
                {
                    listeners[i].appendText(text);
                } catch (Exception e)
                {
                    TLCActivator.logError("Error broadcasting the message", e);
                }
            }
        }
    }

    /**
     * Called to inform us that it has been completed.
     */
    public synchronized void streamClosed()
    {
        // broadcast the message
        for (int i = 0; i < listeners.length; i++)
        {
            try
            {

                if (listeners[i] != null)
                {
                    listeners[i].processFinished();
                }
            } catch (Exception e)
            {
                TLCActivator.logError("Error broadcasting the stream closed event", e);
            }
        }
    }

    /**
     * Retrieves all registered listener managers
     * @return 
     */
    public static IProcessOutputSink[] getRegisteredStreamManagers(String name, int type)
    {
        IConfigurationElement[] decls = Platform.getExtensionRegistry().getConfigurationElementsFor(
                IProcessOutputSink.EXTENSION_ID);

        Vector validExtensions = new Vector();
        for (int i = 0; i < decls.length; i++)
        {
            try
            {
                IProcessOutputSink extension = (IProcessOutputSink) decls[i].createExecutableExtension("class");
                extension.initializeSink(name, type);
                validExtensions.add(extension);
            } catch (CoreException e)
            {
                TLCActivator.logError("Error instatiating the IProcessSink extension", e);
            }
        }
        return (IProcessOutputSink[]) validExtensions.toArray(new IProcessOutputSink[validExtensions.size()]);
    }
}<commit_msg>Hide non API methods by default<commit_after>package org.lamport.tla.toolbox.tool.tlc.output.internal;

import java.util.Vector;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.lamport.tla.toolbox.tool.tlc.TLCActivator;
import org.lamport.tla.toolbox.tool.tlc.output.IProcessOutputSink;

/**
 * A listener broadcasting the stream appending to extensions 
 * @author <NAME>
 * @version $Id$
 */
public class BroadcastStreamListener implements IStreamListener
{
    private IProcessOutputSink[] listeners = null;

    /**
     * 
     * @param streamName
     * @param kind, see constants {@link IProcessOutputSink#TYPE_DEBUG}, {@link IProcessOutputSink#TYPE_ERROR}, {@link IProcessOutputSink#TYPE_OUT}
     */
    public BroadcastStreamListener(String streamName, int kind)
    {
        this.listeners = getRegisteredStreamManagers(streamName, kind);
    }

    /* (non-Javadoc)
     * @see org.eclipse.debug.core.IStreamListener#streamAppended(java.lang.String, org.eclipse.debug.core.model.IStreamMonitor)
     */
    public synchronized void streamAppended(String text, IStreamMonitor monitor)
    {
        // broadcast the message
        for (int i = 0; i < listeners.length; i++)
        {
            if (listeners[i] != null)
            {
                try
                {
                    listeners[i].appendText(text);
                } catch (Exception e)
                {
                    TLCActivator.logError("Error broadcasting the message", e);
                }
            }
        }
    }

    /**
     * Called to inform us that it has been completed.
     */
    public synchronized void streamClosed()
    {
        // broadcast the message
        for (int i = 0; i < listeners.length; i++)
        {
            try
            {

                if (listeners[i] != null)
                {
                    listeners[i].processFinished();
                }
            } catch (Exception e)
            {
                TLCActivator.logError("Error broadcasting the stream closed event", e);
            }
        }
    }

    /**
     * Retrieves all registered listener managers
     * @return 
     */
    private IProcessOutputSink[] getRegisteredStreamManagers(String name, int type)
    {
        IConfigurationElement[] decls = Platform.getExtensionRegistry().getConfigurationElementsFor(
                IProcessOutputSink.EXTENSION_ID);

        Vector validExtensions = new Vector();
        for (int i = 0; i < decls.length; i++)
        {
            try
            {
                IProcessOutputSink extension = (IProcessOutputSink) decls[i].createExecutableExtension("class");
                extension.initializeSink(name, type);
                validExtensions.add(extension);
            } catch (CoreException e)
            {
                TLCActivator.logError("Error instatiating the IProcessSink extension", e);
            }
        }
        return (IProcessOutputSink[]) validExtensions.toArray(new IProcessOutputSink[validExtensions.size()]);
    }
}
{'fraction_non_alphanumeric': 0.0986046511627907, 'fraction_numerical': 0.0009302325581395349, 'mean_word_length': 2.1179313678105367, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '1925222', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1727, 'n_words': 364}