org.forester.util
Class ForesterUtil

java.lang.Object
  extended by org.forester.util.ForesterUtil

public final class ForesterUtil
extends Object


Nested Class Summary
static class ForesterUtil.PhylogenyNodeField
           
 
Field Summary
static String FILE_SEPARATOR
           
static NumberFormat FORMATTER_06
           
static NumberFormat FORMATTER_3
           
static NumberFormat FORMATTER_6
           
static NumberFormat FORMATTER_9
           
static String JAVA_VENDOR
           
static String JAVA_VERSION
           
static String LINE_SEPARATOR
           
static BigDecimal NULL_BD
           
static String OS_ARCH
           
static String OS_NAME
           
static String OS_VERSION
           
static double ZERO_DIFF
           
 
Method Summary
static void appendSeparatorIfNotEmpty(StringBuffer sb, char separator)
           
static Color calcColor(double value, double min, double max, Color minColor, Color maxColor)
          This calculates a color.
static Color calcColor(double value, double min, double max, double mean, Color minColor, Color maxColor, Color meanColor)
          This calculates a color.
static String collapseWhiteSpace(String s)
           
static String colorToHex(Color color)
           
static int countChars(String str, char c)
           
static BufferedWriter createBufferedWriter(File file)
           
static BufferedWriter createBufferedWriter(String name)
           
static File createFileForWriting(String name)
           
static PhylogenyParser createParserDependingFileContents(File file, boolean phyloxml_validate_against_xsd)
           
static PhylogenyParser createParserDependingOnFileType(File file, boolean phyloxml_validate_against_xsd)
           
static PhylogenyParser createParserDependingOnSuffix(String filename, boolean phyloxml_validate_against_xsd)
          Return null if it can not guess the parser to use based on name suffix.
static PhylogenyParser createParserDependingOnUrlContents(URL url, boolean phyloxml_validate_against_xsd)
           
static void ensurePresenceOfDate(PhylogenyNode node)
           
static void ensurePresenceOfDistribution(PhylogenyNode node)
           
static void ensurePresenceOfSequence(PhylogenyNode node)
           
static void ensurePresenceOfTaxonomy(PhylogenyNode node)
           
static void fatalError(String prg_name, String message)
           
static String[] file2array(File file)
           
static List<String> file2list(File file)
           
static SortedSet<String> file2set(File file)
           
static String getCurrentDateTime()
           
static String getFileSeparator()
           
static String getFirstLine(Object source)
           
static String getLineSeparator()
           
static Hashtable<String,Boolean> getPropertyRefs(Phylogeny phylogeny)
          Returns all custom data tag names of this Phylogeny as Hashtable.
static void increaseCountingMap(Map<String,Integer> counting_map, String item_name)
           
static boolean isAllNonEmptyInternalLabelsArePositiveNumbers(Phylogeny phy)
           
static boolean isEmpty(String s)
           
static boolean isEqual(double a, double b)
           
static boolean isEven(int n)
           
static boolean isHasAtLeastNodeWithEvent(Phylogeny phy)
           
static boolean isHasAtLeastOneBranchLengthLargerThanZero(Phylogeny phy)
          Returns true if at least one branch has a length larger than zero.
static boolean isHasAtLeastOneBranchWithSupportValues(Phylogeny phy)
           
static boolean isIntersecting(String[] a, String[] b)
          This determines whether String[] a and String[] b have at least one String in common (intersect).
static double isLargerOrEqualToZero(double d)
           
static boolean isNull(BigDecimal s)
           
static String isReadableFile(File f)
           
static String isReadableFile(String s)
           
static String isWritableFile(File f)
           
static int limitRangeForColor(int i)
          Helper for method "stringToColor".
static SortedMap<Object,Integer> listToSortedCountsMap(List list)
           
static StringBuffer mapToStringBuffer(Map map, String key_value_separator)
           
static String normalizeString(String s, int length, boolean left_pad, char pad_char)
           
static BufferedReader obtainReader(Object source)
           
static StringBuffer pad(double number, int size, char pad, boolean left_pad)
           
static StringBuffer pad(StringBuffer string, int size, char pad, boolean left_pad)
           
static StringBuffer pad(String string, int size, char pad, boolean left_pad)
           
static double parseDouble(String str)
           
static int parseInt(String str)
           
static void postOrderRelabelInternalNodes(Phylogeny phylogeny, int starting_number)
           
static void printArray(Object[] a)
           
static void printCountingMap(Map<String,Integer> counting_map)
           
static void printErrorMessage(String prg_name, String message)
           
static void printProgramInformation(String prg_name, String prg_version, String date)
           
static void printProgramInformation(String prg_name, String prg_version, String date, String email, String www)
           
static void printWarningMessage(String prg_name, String message)
           
static void programMessage(String prg_name, String message)
           
static String removeSuffix(String file_name)
           
static String removeWhiteSpace(String s)
          Removes all white space from String s.
static String replaceIllegalNhCharacters(String nh)
           
static String replaceIllegalNhxCharacters(String nhx)
           
static double round(double value, int decimal_place)
           
static int roundToInt(double d)
          Rounds d to an int.
static int roundToInt(float f)
           
static String sanitizeString(String s)
           
static String stringArrayToString(String[] a)
           
static void transferInternalNamesToBootstrapSupport(Phylogeny phy)
           
static void transferInternalNodeNamesToConfidence(Phylogeny phy)
           
static void transferNodeNameToField(Phylogeny phy, ForesterUtil.PhylogenyNodeField field)
           
static void unexpectedFatalError(String prg_name, Exception e)
           
static void unexpectedFatalError(String prg_name, String message)
           
static void unexpectedFatalError(String prg_name, String message, Exception e)
           
static String wordWrap(String str, int width)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_SEPARATOR

public static final String FILE_SEPARATOR

LINE_SEPARATOR

public static final String LINE_SEPARATOR

JAVA_VENDOR

public static final String JAVA_VENDOR

JAVA_VERSION

public static final String JAVA_VERSION

OS_ARCH

public static final String OS_ARCH

OS_NAME

public static final String OS_NAME

OS_VERSION

public static final String OS_VERSION

ZERO_DIFF

public static final double ZERO_DIFF
See Also:
Constant Field Values

NULL_BD

public static final BigDecimal NULL_BD

FORMATTER_9

public static final NumberFormat FORMATTER_9

FORMATTER_6

public static final NumberFormat FORMATTER_6

FORMATTER_06

public static final NumberFormat FORMATTER_06

FORMATTER_3

public static final NumberFormat FORMATTER_3
Method Detail

appendSeparatorIfNotEmpty

public static final void appendSeparatorIfNotEmpty(StringBuffer sb,
                                                   char separator)

calcColor

public static final Color calcColor(double value,
                                    double min,
                                    double max,
                                    Color minColor,
                                    Color maxColor)
This calculates a color. If value is equal to min the returned color is minColor, if value is equal to max the returned color is maxColor, otherwise a color 'proportional' to value is returned.

Parameters:
value - the value
min - the smallest value
max - the largest value
minColor - the color for min
maxColor - the color for max
Returns:
a Color

calcColor

public static final Color calcColor(double value,
                                    double min,
                                    double max,
                                    double mean,
                                    Color minColor,
                                    Color maxColor,
                                    Color meanColor)
This calculates a color. If value is equal to min the returned color is minColor, if value is equal to max the returned color is maxColor, if value is equal to mean the returned color is meanColor, otherwise a color 'proportional' to value is returned -- either between min-mean or mean-max

Parameters:
value - the value
min - the smallest value
max - the largest value
mean - the mean/median value
minColor - the color for min
maxColor - the color for max
meanColor - the color for mean
Returns:
a Color

collapseWhiteSpace

public static final String collapseWhiteSpace(String s)

colorToHex

public static final String colorToHex(Color color)

countChars

public static final int countChars(String str,
                                   char c)

createBufferedWriter

public static final BufferedWriter createBufferedWriter(File file)
                                                 throws IOException
Throws:
IOException

createBufferedWriter

public static final BufferedWriter createBufferedWriter(String name)
                                                 throws IOException
Throws:
IOException

createFileForWriting

public static final File createFileForWriting(String name)
                                       throws IOException
Throws:
IOException

createParserDependingFileContents

public static final PhylogenyParser createParserDependingFileContents(File file,
                                                                      boolean phyloxml_validate_against_xsd)
                                                               throws FileNotFoundException,
                                                                      IOException
Throws:
FileNotFoundException
IOException

createParserDependingOnFileType

public static final PhylogenyParser createParserDependingOnFileType(File file,
                                                                    boolean phyloxml_validate_against_xsd)
                                                             throws FileNotFoundException,
                                                                    IOException
Throws:
FileNotFoundException
IOException

createParserDependingOnSuffix

public static final PhylogenyParser createParserDependingOnSuffix(String filename,
                                                                  boolean phyloxml_validate_against_xsd)
Return null if it can not guess the parser to use based on name suffix.

Parameters:
filename -
Returns:

createParserDependingOnUrlContents

public static final PhylogenyParser createParserDependingOnUrlContents(URL url,
                                                                       boolean phyloxml_validate_against_xsd)
                                                                throws FileNotFoundException,
                                                                       IOException
Throws:
FileNotFoundException
IOException

ensurePresenceOfDate

public static final void ensurePresenceOfDate(PhylogenyNode node)

ensurePresenceOfDistribution

public static final void ensurePresenceOfDistribution(PhylogenyNode node)

ensurePresenceOfSequence

public static void ensurePresenceOfSequence(PhylogenyNode node)

ensurePresenceOfTaxonomy

public static void ensurePresenceOfTaxonomy(PhylogenyNode node)

fatalError

public static void fatalError(String prg_name,
                              String message)

file2array

public static String[] file2array(File file)
                           throws IOException
Throws:
IOException

file2list

public static final List<String> file2list(File file)
                                    throws IOException
Throws:
IOException

file2set

public static final SortedSet<String> file2set(File file)
                                        throws IOException
Throws:
IOException

getCurrentDateTime

public static final String getCurrentDateTime()

getFileSeparator

public static final String getFileSeparator()

getFirstLine

public static final String getFirstLine(Object source)
                                 throws FileNotFoundException,
                                        IOException
Throws:
FileNotFoundException
IOException

getLineSeparator

public static final String getLineSeparator()

getPropertyRefs

public static final Hashtable<String,Boolean> getPropertyRefs(Phylogeny phylogeny)
Returns all custom data tag names of this Phylogeny as Hashtable. Tag names are keys, values are Boolean set to false.


increaseCountingMap

public static final void increaseCountingMap(Map<String,Integer> counting_map,
                                             String item_name)

isAllNonEmptyInternalLabelsArePositiveNumbers

public static final boolean isAllNonEmptyInternalLabelsArePositiveNumbers(Phylogeny phy)

isEmpty

public static final boolean isEmpty(String s)

isEqual

public static final boolean isEqual(double a,
                                    double b)

isEven

public static final boolean isEven(int n)

isHasAtLeastNodeWithEvent

public static final boolean isHasAtLeastNodeWithEvent(Phylogeny phy)

isHasAtLeastOneBranchLengthLargerThanZero

public static final boolean isHasAtLeastOneBranchLengthLargerThanZero(Phylogeny phy)
Returns true if at least one branch has a length larger than zero.

Parameters:
phy -

isHasAtLeastOneBranchWithSupportValues

public static final boolean isHasAtLeastOneBranchWithSupportValues(Phylogeny phy)

isIntersecting

public static final boolean isIntersecting(String[] a,
                                           String[] b)
This determines whether String[] a and String[] b have at least one String in common (intersect). Returns false if at least one String[] is null or empty.

Parameters:
a - a String[] b a String[]
Returns:
true if both a and b or not empty or null and contain at least one element in common false otherwise

isLargerOrEqualToZero

public static final double isLargerOrEqualToZero(double d)

isNull

public static final boolean isNull(BigDecimal s)

isReadableFile

public static final String isReadableFile(File f)

isReadableFile

public static final String isReadableFile(String s)

isWritableFile

public static final String isWritableFile(File f)

wordWrap

public static final String wordWrap(String str,
                                    int width)

limitRangeForColor

public static final int limitRangeForColor(int i)
Helper for method "stringToColor".

(Last modified: 12/20/03)


listToSortedCountsMap

public static final SortedMap<Object,Integer> listToSortedCountsMap(List list)

mapToStringBuffer

public static final StringBuffer mapToStringBuffer(Map map,
                                                   String key_value_separator)

normalizeString

public static final String normalizeString(String s,
                                           int length,
                                           boolean left_pad,
                                           char pad_char)

obtainReader

public static final BufferedReader obtainReader(Object source)
                                         throws IOException,
                                                FileNotFoundException
Throws:
IOException
FileNotFoundException

pad

public static final StringBuffer pad(double number,
                                     int size,
                                     char pad,
                                     boolean left_pad)

pad

public static final StringBuffer pad(String string,
                                     int size,
                                     char pad,
                                     boolean left_pad)

pad

public static final StringBuffer pad(StringBuffer string,
                                     int size,
                                     char pad,
                                     boolean left_pad)

parseDouble

public static final double parseDouble(String str)
                                throws ParseException
Throws:
ParseException

parseInt

public static final int parseInt(String str)
                          throws ParseException
Throws:
ParseException

postOrderRelabelInternalNodes

public static final void postOrderRelabelInternalNodes(Phylogeny phylogeny,
                                                       int starting_number)

printArray

public static final void printArray(Object[] a)

printCountingMap

public static final void printCountingMap(Map<String,Integer> counting_map)

printErrorMessage

public static final void printErrorMessage(String prg_name,
                                           String message)

printProgramInformation

public static final void printProgramInformation(String prg_name,
                                                 String prg_version,
                                                 String date)

printProgramInformation

public static final void printProgramInformation(String prg_name,
                                                 String prg_version,
                                                 String date,
                                                 String email,
                                                 String www)

printWarningMessage

public static final void printWarningMessage(String prg_name,
                                             String message)

programMessage

public static final void programMessage(String prg_name,
                                        String message)

removeSuffix

public static final String removeSuffix(String file_name)

removeWhiteSpace

public static final String removeWhiteSpace(String s)
Removes all white space from String s.

Returns:
String s with white space removed

replaceIllegalNhCharacters

public static final String replaceIllegalNhCharacters(String nh)

replaceIllegalNhxCharacters

public static final String replaceIllegalNhxCharacters(String nhx)

round

public static final double round(double value,
                                 int decimal_place)

roundToInt

public static final int roundToInt(double d)
Rounds d to an int.


roundToInt

public static final int roundToInt(float f)

sanitizeString

public static final String sanitizeString(String s)

stringArrayToString

public static final String stringArrayToString(String[] a)

transferInternalNamesToBootstrapSupport

public static final void transferInternalNamesToBootstrapSupport(Phylogeny phy)

transferInternalNodeNamesToConfidence

public static final void transferInternalNodeNamesToConfidence(Phylogeny phy)

transferNodeNameToField

public static final void transferNodeNameToField(Phylogeny phy,
                                                 ForesterUtil.PhylogenyNodeField field)

unexpectedFatalError

public static final void unexpectedFatalError(String prg_name,
                                              Exception e)

unexpectedFatalError

public static final void unexpectedFatalError(String prg_name,
                                              String message)

unexpectedFatalError

public static final void unexpectedFatalError(String prg_name,
                                              String message,
                                              Exception e)