goldman.collection
Class StringDigitizer

java.lang.Object
  extended by goldman.collection.StringDigitizer
All Implemented Interfaces:
Digitizer<String>, PrefixFreeDigitizer<String>

public class StringDigitizer
extends Object
implements PrefixFreeDigitizer<String>

The StringDigitizer class is an implementation of the Digitizer interface for a string composed of only the 26 lower case letters.
REQUIRES: all strings provided as arguments contain only the 26 lower case letters


Constructor Summary
StringDigitizer(int alphabetSize)
           
 
Method Summary
 String formatDigit(String x, int place)
           
 int getBase()
          Returns the base.
 int getDigit(String x, int place)
          Returns the value of digit place for element x.
 boolean isPrefixFree()
          Returns true if and only if the digitizer guarantees that no element is a prefix of another.
 int numDigits(String x)
          Returns the number of digits in the element x.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringDigitizer

public StringDigitizer(int alphabetSize)
Method Detail

getBase

public int getBase()
Description copied from interface: Digitizer
Returns the base. Observe that a base b digit takes on values from 0 to b-1.

Specified by:
getBase in interface Digitizer<String>
Returns:
the base of the alphabet that includes the end of string character.

isPrefixFree

public boolean isPrefixFree()
Description copied from interface: Digitizer
Returns true if and only if the digitizer guarantees that no element is a prefix of another.

Specified by:
isPrefixFree in interface Digitizer<String>
Returns:
true since this is a prefix free digitizer.

numDigits

public int numDigits(String x)
Description copied from interface: Digitizer
Returns the number of digits in the element x.

Specified by:
numDigits in interface Digitizer<String>
Parameters:
x - the given string
Returns:
the number of digits in the string including the end of string character.

getDigit

public int getDigit(String x,
                    int place)
Description copied from interface: Digitizer
Returns the value of digit place for element x.

Specified by:
getDigit in interface Digitizer<String>
Parameters:
x - the given string
place - the place of the desired digit, where the leftmost digit is place 0
Returns:
the integer value mapped to by the digit in the given place

formatDigit

public String formatDigit(String x,
                          int place)
Specified by:
formatDigit in interface Digitizer<String>
Parameters:
x - the given string
place - the place for the desired digit
Returns:
a string with the digit in the given place where "\#" is used %for the end of string character.