<commit_before>package net.java.sip.communicator.impl.protocol.irc;

import java.util.ArrayList;
import java.util.List;

import com.ircclouds.irc.api.domain.messages.ChannelModeMessage;

public class ModeParser
{
    private final List<ModeEntry> modes = new ArrayList<ModeEntry>();
    private int index = 0;
    private String[] params;
    
    public ModeParser(ChannelModeMessage message)
    {
        this(message.getModeStr());
    }
    
    protected ModeParser(String modestring)
    {
        String[] parts = modestring.split(" ");
        String mode = parts[0];
        this.params = new String[parts.length-1];
        System.arraycopy(parts, 1, this.params, 0, parts.length-1);
        parse(mode);
    }

    private void parse(String modestring)
    {
        boolean adding = true;
        for(char c : modestring.toCharArray())
        {
            switch(c)
            {
            case '+':
                adding = true;
                break;
            case '-':
                adding = false;
                break;
            default:
                try
                {
                    ModeEntry entry = process(adding, c);
                    modes.add(entry);
                }
                catch(IllegalArgumentException e)
                {
                    System.out.println("Unknown mode encountered: '"+c+"' (mode string '"+modestring+"')");
                }
                break;
            }
        }
    }
    
    private ModeEntry process(boolean add, char mode)
    {
        switch(mode)
        {
        case 'O':
            return new ModeEntry(add, Mode.bySymbol(mode), this.params[this.index++]);
        case 'o':
            return new ModeEntry(add, Mode.bySymbol(mode), this.params[this.index++]);
        case 'v':
            return new ModeEntry(add, Mode.bySymbol(mode), this.params[this.index++]);
        case 'l':
            String[] params = (add ? new String[] { this.params[this.index++] } : new String[]{});
            return new ModeEntry(add, Mode.bySymbol(mode), params);
        default:
            throw new IllegalArgumentException(""+mode);
        }
    }
    
    public List<ModeEntry> getModes()
    {
        return modes;
    }
    
    public static class ModeEntry
    {
        private final boolean added;
        private final Mode mode;
        private final String[] params;
        
        protected ModeEntry(boolean add, Mode mode, String... params)
        {
            this.added = add;
            this.mode = mode;
            this.params = params;
        }
        
        public boolean isAdded()
        {
            return this.added;
        }
        
        public Mode getMode()
        {
            return this.mode;
        }
        
        public String[] getParams()
        {
            return this.params;
        }
    }
}
<commit_msg>Tweaks and documentation for ModeParser.<commit_after>package net.java.sip.communicator.impl.protocol.irc;

import java.util.ArrayList;
import java.util.List;

import com.ircclouds.irc.api.domain.messages.ChannelModeMessage;

public class ModeParser
{
    /**
     * List of parsed, processed modes.
     */
    private final List<ModeEntry> modes = new ArrayList<ModeEntry>();

    /**
     * Index of current parameter.
     */
    private int index = 0;

    /**
     * Additional parameters
     */
    private String[] params;

    /**
     * Constructor for parsing based on an irc-api ChannelModeMessage.
     * 
     * @param message ChannelModeMessage describing mode changes
     */
    public ModeParser(ChannelModeMessage message)
    {
        this(message.getModeStr());
    }

    /**
     * Constructor for initiating mode parser and parsing mode string.
     * 
     * @param modestring mode string that should be parsed
     */
    protected ModeParser(String modestring)
    {
        String[] parts = modestring.split(" ");
        String mode = parts[0];
        this.params = new String[parts.length - 1];
        System.arraycopy(parts, 1, this.params, 0, parts.length - 1);
        parse(mode);
    }

    /**
     * Parse a complete mode string and extract individual mode entries.
     * 
     * @param modestring full mode string
     */
    private void parse(String modestring)
    {
        boolean adding = true;
        for (char c : modestring.toCharArray())
        {
            switch (c)
            {
            case '+':
                adding = true;
                break;
            case '-':
                adding = false;
                break;
            default:
                try
                {
                    ModeEntry entry = process(adding, c);
                    modes.add(entry);
                }
                catch (IllegalArgumentException e)
                {
                    System.out.println("Unknown mode encountered: '" + c
                        + "' (mode string '" + modestring + "')");
                }
                break;
            }
        }
    }

    /**
     * Process mode character given state of addition/removal.
     * 
     * @param add indicates whether mode change is addition or removal
     * @param mode mode character
     * @return returns an entry that contains all parts of an individual mode
     *         change
     */
    private ModeEntry process(boolean add, char mode)
    {
        switch (mode)
        {
        case 'O':
            return new ModeEntry(add, Mode.bySymbol(mode),
                this.params[this.index++]);
        case 'o':
            return new ModeEntry(add, Mode.bySymbol(mode),
                this.params[this.index++]);
        case 'v':
            return new ModeEntry(add, Mode.bySymbol(mode),
                this.params[this.index++]);
        case 'l':
            String[] params = (add ? new String[]
            { this.params[this.index++] } : new String[] {});
            return new ModeEntry(add, Mode.bySymbol(mode), params);
        default:
            throw new IllegalArgumentException("" + mode);
        }
    }

    /**
     * Get list of modes.
     * 
     * @return returns list of parsed modes
     */
    public List<ModeEntry> getModes()
    {
        return modes;
    }

    /**
     * Class for single mode entry, optionally with corresponding parameter(s).
     */
    public static class ModeEntry
    {
        /**
         * Flag to indicate addition or removal of mode.
         */
        private final boolean added;

        /**
         * Type of mode.
         */
        private final Mode mode;

        /**
         * Optional additional parameter(s).
         */
        private final String[] params;

        /**
         * Constructor.
         * 
         * @param add true if mode is added, false if it is removed
         * @param mode type of mode
         * @param params optional, additional parameters
         */
        private ModeEntry(boolean add, Mode mode, String... params)
        {
            this.added = add;
            this.mode = mode;
            this.params = params;
        }

        /**
         * Added or removed.
         * 
         * @return returns true if added, removed otherwise
         */
        public boolean isAdded()
        {
            return this.added;
        }

        /**
         * Get type of mode
         * 
         * @return returns enum instance of mode
         */
        public Mode getMode()
        {
            return this.mode;
        }

        /**
         * Get additional parameters
         * 
         * @return returns array of additional parameters if any
         */
        public String[] getParams()
        {
            return this.params;
        }
    }
}

{'fraction_non_alphanumeric': 0.10042762731631463, 'fraction_numerical': 0.0015550084229622911, 'mean_word_length': 1.4524944391483954, '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': '1087461', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1946, 'n_words': 545}