finiteAutomata
Class Util

java.lang.Object
  extended by finiteAutomata.Util

public class Util
extends java.lang.Object

Library of public static utility methods to support the classes in the finiteAutomata package.

Version:
Fall 2007
Author:
Barbara Wahl

Field Summary
protected static java.util.Scanner scanner
          Scanner for reading keyboard input
 
Constructor Summary
Util()
           
 
Method Summary
static boolean answerIsYes()
          Reads the next String from keyboard input and decides if it is a "yes" answer.
static boolean hasRepeat(java.lang.String inString)
          Returns true if the given string contains at least one repeated character.
static boolean hasWhiteSpace(java.lang.String inString)
          Returns true if the given string contains at least one whitespace character.
static int intLogTwo(int n)
          Returns the nearest integer to log-base-2 of the given integer.
static double logTwo(int n)
          Returns log-base-two of the given integer.
static void main(java.lang.String[] args)
           
static void printString(java.lang.String inString)
          Prints "epsilon" if the given String is empty; otherwise, prints the given String.
static boolean readBoolean()
          Repeatedly prompts user to enter TRUE or FALSE.
static int readNum()
          Reads the next String from keyboard input and parses it as a non-negative integer.
static java.lang.String readString()
          Returns the next String read from keyboard input.
protected static int stringToInt(java.lang.String s)
          Returns the integer value of the given (short) string of digits.
static int twoPower(int n)
          Returns the given power of 2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scanner

protected static java.util.Scanner scanner
Scanner for reading keyboard input

Constructor Detail

Util

public Util()
Method Detail

twoPower

public static int twoPower(int n)
Returns the given power of 2.

Parameters:
n - integer power of 2 to be calculated
Returns:
2^n

logTwo

public static double logTwo(int n)
Returns log-base-two of the given integer.

Parameters:
n - integer value whose log is to be calculated
Returns:
log2(n)

intLogTwo

public static int intLogTwo(int n)
Returns the nearest integer to log-base-2 of the given integer.

Parameters:
n - integer value whose log is to be calculated
Returns:
log2(n) rounded to nearest integer

printString

public static void printString(java.lang.String inString)
Prints "epsilon" if the given String is empty; otherwise, prints the given String.

Parameters:
inString - String to be printed
Precondition:
inString is not null

readString

public static java.lang.String readString()
Returns the next String read from keyboard input.


readBoolean

public static boolean readBoolean()
Repeatedly prompts user to enter TRUE or FALSE.

Returns:
true if user enters a string starting with 't', 'T', 'y', or 'Y'; false if user enters a string starting with 'f', 'F', 'n', or 'N'.

answerIsYes

public static boolean answerIsYes()
Reads the next String from keyboard input and decides if it is a "yes" answer.

Returns:
true iff user enters a string starting with 'y' or 'Y'

readNum

public static int readNum()
Reads the next String from keyboard input and parses it as a non-negative integer.

Returns:
the non-negative integer form of the String read from keyboard input (if possible), otherwise -1

stringToInt

protected static int stringToInt(java.lang.String s)
Returns the integer value of the given (short) string of digits.

Parameters:
s - the String of digits to be converted
Returns:
the integer equivalent of s
Precondition:
s is not too long (fewer than 10 chars will be okay)

hasWhiteSpace

public static boolean hasWhiteSpace(java.lang.String inString)
Returns true if the given string contains at least one whitespace character.

Parameters:
inString - the string to be examined
Returns:
true iff at least one character in inString is whitespace
Precondition:
inString is not null

hasRepeat

public static boolean hasRepeat(java.lang.String inString)
Returns true if the given string contains at least one repeated character.

Parameters:
inString - the string to be examined
Returns:
true iff at least one character in inString is repeated
Precondition:
inString is not null

main

public static void main(java.lang.String[] args)