/*
  James Little, 29/3/01
  COSC 241
  
  IO.java

  Implemented for Scrabble application
*/

package jlittle_ex5;

import java.util.*;
import java.io.*;

public class IO {

    private static BufferedReader reader =
	new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer tokenizedInput = new StringTokenizer("");
    private static String inputString = "";
    

    // get last token
    public static String getLast() {  // the last one
	return inputString;
    }

    // count tokens
    public static int countTokens() {
	return tokenizedInput.countTokens();  // count da' tokens
    }

    // read new line
    public static String readLine() {
	inputString = null;  // delete input
	tokenizedInput = new StringTokenizer(""); // another string tokenizer

	try {
	    inputString = reader.readLine();     
	} catch (IOException e) {
	    System.out.println("Error: " + e.getMessage());
	    System.exit(-1);  
	}
	tokenizedInput = (inputString != null) ?
	    new StringTokenizer(inputString) :
	    new StringTokenizer("");  
	return inputString; 
    }

    // get next token
    public static String nextToken() {
	try {
	    return tokenizedInput.nextToken();
	} catch (NoSuchElementException e) {
	    System.out.println("Error: no more tokens to get.");
	    System.exit(-1);
	    return "This shouldn't be reached"; // thats for sure.. System should have exited.
	}
    }
}
