finiteAutomata
Class Alphabet

java.lang.Object
  extended by finiteAutomata.Alphabet

public class Alphabet
extends java.lang.Object

A non-empty set of symbols. Alphabets are naturally associated with both finite automata (input symbols) and grammars (terminal symbols).

Version:
Fall 2007
Author:
Barbara Wahl

Field Summary
protected  java.lang.StringBuffer alpha
          alphabet symbols
 
Constructor Summary
Alphabet(java.lang.String inString)
          creates an Alphabet from the characters in a given string.
 
Method Summary
 char charAt(int i)
          Returns the i-th symbol in this Alphabet.
 boolean contains(char c)
          Determines if a given character is a symbol in this Alphabet.
 java.util.Vector getLanguage(int n)
          Generates the language of all strings over this Alphabet up to a given length.
 boolean indexArray(java.lang.String inString, int[] array)
          Converts each character in the given String to its position in this Alphabet.
 int indexOf(char c)
          Determines the position of a given character in this Alphabet.
static void main(java.lang.String[] args)
           
static void printLanguage(java.util.Vector v)
          Prints a given Vector of objects (the "toString()" version of each object is printed).
 int size()
          Returns number of symbols in this Alphabet.
 java.lang.String toPrettyString()
          Converts this Alphabet to a String of symbols punctuated with braces and commas.
 java.lang.String toString()
          Converts this Alphabet to a String of symbols.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

alpha

protected java.lang.StringBuffer alpha
alphabet symbols

Constructor Detail

Alphabet

public Alphabet(java.lang.String inString)
creates an Alphabet from the characters in a given string.

Parameters:
inString - String containing the desired alphabet characters in the desired lexicographic order
Precondition:
inString is a non-empty string, inString has no repeated characters, inString has no whitespace characters
Postcondition:
creates an Alphabet object whose symbols are the characters in inString
Method Detail

size

public int size()
Returns number of symbols in this Alphabet.

Returns:
alpha.length()

contains

public boolean contains(char c)
Determines if a given character is a symbol in this Alphabet.

Parameters:
c - char to be located
Returns:
true iff the given character is in this Alphabet

indexOf

public int indexOf(char c)
Determines the position of a given character in this Alphabet.

Parameters:
c - char to be located
Returns:
non-negative integer position of c in this Alphabet, or -1 if c not found

charAt

public char charAt(int i)
Returns the i-th symbol in this Alphabet.

Parameters:
i - int position of interest
Returns:
char at position i in this Alphabet
Precondition:
0 <= i < this.size()

toString

public java.lang.String toString()
Converts this Alphabet to a String of symbols.

Overrides:
toString in class java.lang.Object
Returns:
a String version of this Alphabet with no punctuation or spaces

toPrettyString

public java.lang.String toPrettyString()
Converts this Alphabet to a String of symbols punctuated with braces and commas.

Returns:
a pretty String version of this Alphabet

indexArray

public boolean indexArray(java.lang.String inString,
                          int[] array)
Converts each character in the given String to its position in this Alphabet.

Parameters:
inString - the String of characters to be converted
array - of integers for returning the list of positions
Returns:
true iff every character in inString is a symbol in this Alphabet
Precondition:
inString is not null, and array.length >= inString.length()
Postcondition:
if every character in inString is a symbol in this Alphabet, the initial segment of array will contain the position numbers of the corresponding characters in inString

printLanguage

public static void printLanguage(java.util.Vector v)
Prints a given Vector of objects (the "toString()" version of each object is printed).

Parameters:
v - Vector of objects to be printed
Precondition:
v is not null and has no null elements
Postcondition:
prints the objects in v, one per line; if an object has toString() value == "", prints "epsilon" instead of ""

getLanguage

public java.util.Vector getLanguage(int n)
Generates the language of all strings over this Alphabet up to a given length.

Parameters:
n - maximum string length
Returns:
Vector containing language alpha* (in lexicographic order) up through strings of length n; language strings are stored in the Vector as StringBuffer objects.
Precondition:
n >= 0

main

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