/** * A class that parses input strings of the form: * ,| * Where all spaces are ignored. * This parser assumes that there are no ',' or '|' characters * in the last name, first name, or ID #. * @author bederson */ public class Parser { // These hold the data as they are parsed private String lastName, firstName, studentId; // These are true when the relavant word has been parsed private boolean firstNameComplete, lastNameComplete; private char charValue; // The current character being analyzed /** * Resets the state of the parser to the initial state. * This is an internal method and is used internally in support * of the parsers. */ private void reset() { firstNameComplete = false; lastNameComplete = false; lastName = ""; firstName = ""; studentId = ""; } /** * Parse the input string. When it is complete, the class * instance variables holding first name, last name and ID # will * be set, and can be accessed through the appropriate getter methods. * @see getFirstName() * @see getLastName() * @see getStudentID() * @param data The input string to parse */ void parseInputOne(String data) { // This version is implemented with a sequence of if/else statements reset(); // Crucial to reset parser before start, or there will // be problems if a second string is parsed for (int i=0; i