recognizer
Class Utils

java.lang.Object
  extended by recognizer.Utils

public class Utils
extends java.lang.Object

Library of program-independent static methods.

Author:
Francois Mairesse, http://www.mairesse.co.uk

Constructor Summary
Utils()
           
 
Method Summary
static int countMatches(java.lang.String regex, java.lang.String text)
          Counts the number of times a pattern appears in a string.
static void printHash(java.util.Hashtable<? extends java.lang.Object,? extends java.lang.Object> ht, java.io.PrintStream out)
          Prints the content of a hashtable containing strings to the standard output.
static void printMap(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map, java.io.PrintStream out)
          Prints the content of a Map containing strings to the standard output.
static java.lang.String readDir(java.io.File dir)
          Reads the content of all files in a directory into a single string.
static java.lang.String readFile(java.io.File file)
          Reads the content of a text file into a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

countMatches

public static int countMatches(java.lang.String regex,
                               java.lang.String text)
Counts the number of times a pattern appears in a string.

Parameters:
regex - regular expression string to be matched, it must be in the appropriate format to be compiled into a Pattern object.
text - input text.
Returns:
number of matches found.

printHash

public static void printHash(java.util.Hashtable<? extends java.lang.Object,? extends java.lang.Object> ht,
                             java.io.PrintStream out)
                      throws java.lang.Exception
Prints the content of a hashtable containing strings to the standard output.

Parameters:
ht - hashtable with string keys and values that can be represented using their toString() method.
out - output stream.
Throws:
java.lang.Exception

printMap

public static void printMap(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map,
                            java.io.PrintStream out)
                     throws java.lang.Exception
Prints the content of a Map containing strings to the standard output.

Parameters:
map - map with string keys and values that can be represented using their toString() method.
out - output stream.
Throws:
java.lang.Exception

readFile

public static java.lang.String readFile(java.io.File file)
                                 throws java.lang.Exception
Reads the content of a text file into a string.

Parameters:
file - text file.
Returns:
string containing the text, with a line separator character between lines.
Throws:
java.lang.Exception

readDir

public static java.lang.String readDir(java.io.File dir)
                                throws java.lang.Exception
Reads the content of all files in a directory into a single string.

Parameters:
dir - directory containing text files.
Returns:
string containing the text, with a line separator character between lines.
Throws:
java.lang.Exception