package simulator;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/*
 * DataReader.java
 * Created on Feb 2, 2005
 *
 */

/**
 *  DataReader - This class reads 1 line from a file at a time.  
 *  @author Ping
 *
 */
public class DataReader
{
    public static String COMMENT_MARKER = "*";
    Scanner scanner;
    
    public DataReader(String fileName)throws FileNotFoundException
    {
    	scanner = new Scanner(new File(fileName));
    }
    
    /**
     * This function reads a line of data from the file.
     * This ignores empty lines as well as commented lines.
     * @return
     */
    public String readDataLine()
    {
        String line = null;
        if(scanner.hasNextLine())
        {
            line = scanner.nextLine().trim();
            // read a comment or an empty line
            while(line.equals("") || 
                  line.startsWith(COMMENT_MARKER))
            {
                if(scanner.hasNextLine())
                {
                    // make sure there is something to read
                    line = scanner.nextLine().trim();
                }
                else
                {
                    // if we have run out of stuff to read, return null
                    line = null;
                }
            }
        }
        return line;
    }
    
    /**
     * This function returns true if the file has more lines to be
     * read in.
     * @return
     */
    public boolean hasMoreLines()
    {
        return scanner.hasNextLine();
    }
}
