/*
 * Copyright (c) 2006-2014 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.parser.irc.events;

import com.dmdirc.parser.events.DataInEvent;
import com.dmdirc.parser.interfaces.Parser;
import com.dmdirc.parser.irc.IRCParser;
import com.dmdirc.parser.irc.IRCReader.ReadLine;

import java.time.LocalDateTime;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Called on every incoming line BEFORE parsing.
 *
 * This extends the standard DataInEvent to provide access to IRC-Specific bits.
 */
public class IRCDataInEvent extends DataInEvent {

    private final ReadLine line;
    private final String[] tokenisedData;
    private final String action;

    public IRCDataInEvent(final IRCParser parser, final LocalDateTime date, final ReadLine line) {
        super(parser, date, checkNotNull(line).getLine());
        this.line = line;
        tokenisedData = line.getTokens();

        // Action is slightly more complicated than for DataOut
        if (tokenisedData.length > 1) {
            if (tokenisedData[0].length() > 0 && tokenisedData[0].charAt(0) == ':') {
                if (tokenisedData[1].equalsIgnoreCase("NOTICE") && !parser.got001) {
                    action = "NOTICE AUTH";
                } else {
                    action = tokenisedData[1].toUpperCase();
                }
            } else if (tokenisedData[0].equalsIgnoreCase("NOTICE")) {
                action = "NOTICE AUTH";
            } else {
                action = tokenisedData[0].toUpperCase();
            }
        } else {
            action = "";
        }
    }

    public String[] getTokenisedData() {
        return tokenisedData;
    }

    public ReadLine getLine() {
        return line;
    }

    public String getAction() {
        return action;
    }
}

@@ -1737,16 +1737,47 @@
  action;
+%0A    private final int numeric;
 %0A%0A    pu
@@ -2669,24 +2669,160 @@
 %22;%0A        %7D
+%0A%0A        int num = -1;%0A        try %7B num = Integer.parseInt(action); %7D catch (final NumberFormatException e) %7B %7D%0A        numeric = num;
 %0A    %7D%0A%0A    
@@ -3015,11 +3015,142 @@
 n;%0A    %7D
+%0A%0A    public boolean isNumeric() %7B%0A        return numeric != -1;%0A    %7D%0A%0A    public int getNumeric() %7B%0A        return numeric;%0A    %7D
 %0A%7D%0A

Add numeric stuff to IRCDataInEvent