/*
 * RegAction.java
 *
 */
package FrequencyListPopulations;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Adam Nelson
 * 
 * RegAction matches the input string from ReadFromTextFile against its 
 * intended format, and then adds the ints and Strings to ArrayLists.
 */
public class RegAction {

    private ArrayList<String> stringList = new ArrayList<String>();
    private ArrayList<Integer> intList = new ArrayList<Integer>();

    /**
     *
     * 
     * Finds a match and adds components from the input string to ArrayLists.
     * 
     * @return void
     * 
     */
    public void listAdder(String line) throws Exception {
        Pattern p = Pattern.compile("\\s*(-?[\\d]+)\\s*([\\S\\w]+)"); //"\\(hello\\)"
        Matcher m = p.matcher(line);

        
        if (m.matches()) {
            
            int x = Integer.parseInt(m.group(1));
            String word = m.group(2);
            intList.add(x);
            stringList.add(word);

        } else {
            throw new Exception("Error: There was not a match in the text file provided");
        }
         
    }
    
    public ArrayList<String> getStringList(){
        return stringList;
    }
    
    public ArrayList<Integer> getIntList(){
        return intList;
    }
}
