Support
Class Support

java.lang.Object
  |
  +--Support.Support

public abstract class Support
extends java.lang.Object

Contains miscellaneous static support functions shared by the rest of the system.

Version:
Created 4 April 2003
Author:
Dan Tappan

Field Summary
static boolean ENABLE_LOGGING
           
private static boolean PRINT_WARNING_STACK_TRACE
           
static java.util.Random randomizer
           
static java.lang.String WINDOWS_NEWLINE
           
 
Constructor Summary
Support()
           
 
Method Summary
static java.lang.String chop(java.lang.String string)
          Returns a string with its trailing character removed.
static boolean compareReal(double real1, double real2, double tolerance)
          Returns whether two real numbers are equal within a tolerance.
static java.lang.String formatReal(double value)
          Returns a float value formatted as #.##.
static java.lang.String formatReal(float value)
          Returns a float value formatted as #.##.
static java.util.ArrayList getFlattenedList(java.util.ArrayList array_list)
          Returns a one-dimensional array list from a multidimensional array list (i.e., one containing other array lists).
static java.util.ArrayList getUniqueArrayList(java.util.ArrayList array_list)
          Returns an array list with any duplicate elements removed.
static void setRandomSeed(long seed)
          Initializes the centralized random-number generator used by the entire system.
static java.lang.String toPrettyString(java.lang.String string)
          Returns a string from any well-formed toString() indented according to the braces.
static java.lang.String toSplitString(java.util.ArrayList list)
          Returns a newline-delimited string composed of the elements of an array list.
static java.lang.String toSplitString(java.util.ArrayList list, boolean suppress_newlines)
          Returns an optionally newline-delimited string composed of the elements of an array list.
static java.lang.String toSplitString(java.util.Hashtable hash_table)
          Returns a newline-delimited string composed of the elements of an hash table.
static java.lang.String toSplitString(java.util.Hashtable list, boolean suppress_newlines)
          Returns an optionally newline-delimited string composed of the elements of a hash table.
static java.lang.String[] toStringArray(java.util.ArrayList array_list)
          Returns as a string array the elements of an array list.
static void writeLogEntry(java.lang.String message)
          Writes a formatted log entry to stdout.
static void writeWarning(java.lang.String source, java.lang.String warning)
          Writes a warning to stderr with its source and optionally a stack trace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE_LOGGING

public static final boolean ENABLE_LOGGING
See Also:
Constant Field Values

WINDOWS_NEWLINE

public static final java.lang.String WINDOWS_NEWLINE
See Also:
Constant Field Values

PRINT_WARNING_STACK_TRACE

private static final boolean PRINT_WARNING_STACK_TRACE
See Also:
Constant Field Values

randomizer

public static java.util.Random randomizer
Constructor Detail

Support

public Support()
Method Detail

chop

public static java.lang.String chop(java.lang.String string)
Returns a string with its trailing character removed.

Parameters:
string - - the string

compareReal

public static boolean compareReal(double real1,
                                  double real2,
                                  double tolerance)
Returns whether two real numbers are equal within a tolerance.

Parameters:
real1 - - the first real number
real2 - - the second real number
tolerance - - the tolerance
Returns:
the outcome

formatReal

public static java.lang.String formatReal(float value)
Returns a float value formatted as #.##. This is a convenience function used mainly in toString() output and should not be relied upon for general coding.

Parameters:
value - - the value
Returns:
the formatted value

formatReal

public static java.lang.String formatReal(double value)
Returns a float value formatted as #.##. This is a convenience function used mainly in toString() output and should not be relied upon for general coding.

Parameters:
value - - the value
Returns:
the formatted value

getFlattenedList

public static java.util.ArrayList getFlattenedList(java.util.ArrayList array_list)
Returns a one-dimensional array list from a multidimensional array list (i.e., one containing other array lists).

Parameters:
array_list - - the array list
Returns:
the flattened array list

getUniqueArrayList

public static java.util.ArrayList getUniqueArrayList(java.util.ArrayList array_list)
Returns an array list with any duplicate elements removed.

Parameters:
array_list - - the array list with duplicated elements
Returns:
the array list without duplicated elements

setRandomSeed

public static void setRandomSeed(long seed)
Initializes the centralized random-number generator used by the entire system.

Parameters:
seed - - the seed; pass System.currentTimeMillis() for nondeterministic runs

toPrettyString

public static java.lang.String toPrettyString(java.lang.String string)
Returns a string from any well-formed toString() indented according to the braces.

Side Effect: writes a warning to stderr if the open and close braces do not match.

Parameters:
string - - the string
See Also:
writeWarning(java.lang.String, java.lang.String)

toSplitString

public static java.lang.String toSplitString(java.util.ArrayList list)
Returns a newline-delimited string composed of the elements of an array list.

Parameters:
list - - the list
Returns:
the string

toSplitString

public static java.lang.String toSplitString(java.util.ArrayList list,
                                             boolean suppress_newlines)
Returns an optionally newline-delimited string composed of the elements of an array list.

Parameters:
list - - the list
suppress_newlines - - whether newline delimiters are disabled
Returns:
the string

toSplitString

public static java.lang.String toSplitString(java.util.Hashtable hash_table)
Returns a newline-delimited string composed of the elements of an hash table.

Parameters:
hash_table - - the hash table
Returns:
the string

toSplitString

public static java.lang.String toSplitString(java.util.Hashtable list,
                                             boolean suppress_newlines)
Returns an optionally newline-delimited string composed of the elements of a hash table.

Parameters:
list - - the hash table
suppress_newlines - - whether newline delimiters are disabled
Returns:
the string

toStringArray

public static java.lang.String[] toStringArray(java.util.ArrayList array_list)
Returns as a string array the elements of an array list.

Parameters:
array_list - - the array list
Returns:
the string array

writeLogEntry

public static void writeLogEntry(java.lang.String message)
Writes a formatted log entry to stdout.


writeWarning

public static void writeWarning(java.lang.String source,
                                java.lang.String warning)
Writes a warning to stderr with its source and optionally a stack trace.

Parameters:
source - - the source of the warning in the form class_name.method_name
warning - - the warning message