com.rapidminer.tools
Class Tools

java.lang.Object
  extended by com.rapidminer.tools.Tools

public class Tools
extends java.lang.Object

Tools for RapidMiner.

Author:
Simon Fischer, Ingo Mierswa

Field Summary
static java.lang.String[] availableTimeZoneNames
           
static java.lang.String[] FALSE_STRINGS
           
static java.lang.String RESOURCE_PREFIX
           
static int SYSTEM_TIME_ZONE
           
static java.lang.String[] TRUE_STRINGS
           
 
Constructor Summary
Tools()
           
 
Method Summary
static void addResourceSource(ResourceSource source)
          Adds a new resource source.
static boolean booleanValue(java.lang.String string, boolean deflt)
           
static java.lang.Class classForName(java.lang.String className)
           
static java.lang.String classNameWOPackage(java.lang.Class c)
          Returns the class name of the given class without the package information.
static void copy(java.io.File srcPath, java.io.File dstPath)
           
static void delete(java.io.File file)
           
static java.lang.String escapeXML(java.lang.String string)
          Replaces angle brackets by html entities.
static void findImplementationsInJar(java.lang.ClassLoader loader, java.util.jar.JarFile jar, java.lang.Class<?> superClass, java.util.List<java.lang.String> implementations)
           
static void findImplementationsInJar(java.util.jar.JarFile jar, java.lang.Class superClass, java.util.List<java.lang.String> implementations)
           
static java.io.File findSourceFile(java.lang.StackTraceElement e)
           
static java.lang.String formatDate(java.util.Date date)
          Format date as a short time string.
static java.lang.String formatDateTime(java.util.Date date)
          Format date as a short time string.
static java.lang.String formatDuation(long milliseconds)
          Format the given amount of milliseconds as a human readable string.
static java.lang.String formatIntegerIfPossible(double value)
          Returns a number string with no fraction digits if possible.
static java.lang.String formatIntegerIfPossible(double value, int numberOfDigits)
          Returns a number string with no fraction digits if possible.
static java.lang.String formatNumber(double value)
          Returns a formatted string of the given number (number format with usually three fraction digits).
static java.lang.String formatNumber(double value, int numberOfDigits)
          Returns a formatted string of the given number (uses the property rapidminer.gui.fractiondigits.numbers if the given number of digits is smaller than 0 (usually 3)).
static java.lang.String formatPercent(double value)
          Returns a formatted string of the given number (percent format with two fraction digits).
static java.lang.String formatTime(java.util.Date date)
          Format date as a short time string.
static java.lang.String[] getAllTimeZones()
           
static java.nio.charset.Charset getDefaultEncoding()
          This method tries to identify the encoding if a GUI is running and a process is defined.
static java.io.File getFile(java.io.File parent, java.lang.String name)
          Creates a file relative to the given parent if name is not an absolute file name.
static void getFirstToken(java.io.StreamTokenizer tokenizer)
          Delivers the next token and skip empty lines.
static void getLastToken(java.io.StreamTokenizer tokenizer, boolean endOfFileOk)
          Delivers the next token and checks if its the end of line.
static java.lang.String getLineSeparator()
          Returns the correct line separator for the current operating system.
static java.lang.String getLineSeparators(int number)
          Returns the correct line separator for the current operating system concatenated for the given number of times.
static void getNextToken(java.io.StreamTokenizer tokenizer)
          Delivers the next token and checks for an unexpected end of line or file.
static java.util.Calendar getPreferredCalendar()
           
static java.util.TimeZone getPreferredTimeZone()
           
static int getPreferredTimeZoneIndex()
           
static java.io.BufferedReader getReader(java.io.File file, java.nio.charset.Charset encoding)
          This method checks if the given file is a Zip file containing one entry (in case of file extension .zip).
static java.lang.String getRelativePath(java.io.File firstFile, java.io.File secondFile)
          Returns the relative path of the first file resolved against the second.
static java.net.URL getResource(java.lang.ClassLoader loader, java.lang.String name)
           
static java.net.URL getResource(java.lang.ClassLoader loader, java.lang.String prefix, java.lang.String name)
           
static java.net.URL getResource(java.lang.String name)
          Returns the desired resource.
static java.util.TimeZone getTimeZone(int index)
           
static boolean isEqual(double d1, double d2)
          Returns true if the difference between both numbers is smaller than IS_ZERO.
static boolean isGreater(double d1, double d2)
          Returns true if the d1 is greater than d2 and they are not equal.
static boolean isGreaterEqual(double d1, double d2)
          Returns true if the d1 is greater than d1 or both are equal, or if one of the values is NaN
static boolean isLess(double d1, double d2)
          Returns true if the d1 is less than d2 and they are not equal.
static boolean isLessEqual(double d1, double d2)
          Returns true if the d1 is less than d1 or both are equal.
static boolean isNotEqual(double d1, double d2)
          Returns no isEqual(double, double).
static boolean isZero(double d)
          Returns isEqual(double, double) for d and 0.
static java.lang.Process launchFileEditor(java.io.File file, int line)
           
static java.lang.String[] mergeQuotedSplits(java.lang.String line, java.lang.String[] splittedTokens, java.lang.String quoteString)
          Deprecated. Please use quotedSplit(String, Pattern, char, char) or quotedSplit(String, Pattern) instead
static java.lang.String ordinalNumber(int n)
          Returns the name for an ordinal number.
static void prependResourceSource(ResourceSource source)
          Adds a new resource source before the others.
static java.lang.String[] quotedSplit(java.lang.String line, java.util.regex.Pattern separatorPattern)
          Splits the given line according to the given separator pattern while only those separators will be regarded not lying inside of a quoting string.
static java.lang.String[] quotedSplit(java.lang.String line, java.util.regex.Pattern separatorPattern, char quotingChar, char escapeChar)
          Splits the given line according to the given separator pattern while only those separators will be regarded not lying inside of a quoting string.
static java.lang.String readOutput(java.io.BufferedReader in)
          Reads the output of the reader and delivers it as string.
static java.lang.String readTextFile(java.io.File file)
           
static java.lang.String readTextFile(java.io.Reader r)
           
static java.lang.String removeAllLineSeparators(java.lang.String text)
          Removes all possible line feed character combinations.
static void sendEmail(java.lang.String address, java.lang.String subject, java.lang.String content)
          Sends a mail to the given address, using the specified subject and contents.
static void setFormatLocale(java.util.Locale locale)
           
static java.lang.String transformAllLineSeparators(java.lang.String text)
          Replaces all possible line feed character combinations by "\n".
static void waitForEOL(java.io.StreamTokenizer tokenizer)
          Skips all tokens before next end of line (EOL).
static void waitForProcess(Operator operator, java.lang.Process process, java.lang.String name)
          Waits for process to die and writes log messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_PREFIX

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

availableTimeZoneNames

public static java.lang.String[] availableTimeZoneNames

SYSTEM_TIME_ZONE

public static final int SYSTEM_TIME_ZONE
See Also:
Constant Field Values

TRUE_STRINGS

public static final java.lang.String[] TRUE_STRINGS

FALSE_STRINGS

public static final java.lang.String[] FALSE_STRINGS
Constructor Detail

Tools

public Tools()
Method Detail

setFormatLocale

public static void setFormatLocale(java.util.Locale locale)

getAllTimeZones

public static java.lang.String[] getAllTimeZones()

getTimeZone

public static java.util.TimeZone getTimeZone(int index)

getPreferredTimeZone

public static java.util.TimeZone getPreferredTimeZone()

getPreferredTimeZoneIndex

public static int getPreferredTimeZoneIndex()

getPreferredCalendar

public static java.util.Calendar getPreferredCalendar()

formatPercent

public static java.lang.String formatPercent(double value)
Returns a formatted string of the given number (percent format with two fraction digits).


formatNumber

public static java.lang.String formatNumber(double value)
Returns a formatted string of the given number (number format with usually three fraction digits).


formatNumber

public static java.lang.String formatNumber(double value,
                                            int numberOfDigits)
Returns a formatted string of the given number (uses the property rapidminer.gui.fractiondigits.numbers if the given number of digits is smaller than 0 (usually 3)).


formatIntegerIfPossible

public static java.lang.String formatIntegerIfPossible(double value)
Returns a number string with no fraction digits if possible. Otherwise the default number of digits will be returned.


formatIntegerIfPossible

public static java.lang.String formatIntegerIfPossible(double value,
                                                       int numberOfDigits)
Returns a number string with no fraction digits if possible. Otherwise the given number of digits will be returned.


formatTime

public static java.lang.String formatTime(java.util.Date date)
Format date as a short time string.


formatDate

public static java.lang.String formatDate(java.util.Date date)
Format date as a short time string.


formatDateTime

public static java.lang.String formatDateTime(java.util.Date date)
Format date as a short time string.


formatDuation

public static java.lang.String formatDuation(long milliseconds)
Format the given amount of milliseconds as a human readable string.


ordinalNumber

public static java.lang.String ordinalNumber(int n)
Returns the name for an ordinal number.


isEqual

public static boolean isEqual(double d1,
                              double d2)
Returns true if the difference between both numbers is smaller than IS_ZERO.


isZero

public static boolean isZero(double d)
Returns isEqual(double, double) for d and 0.


isNotEqual

public static boolean isNotEqual(double d1,
                                 double d2)
Returns no isEqual(double, double).


isGreater

public static boolean isGreater(double d1,
                                double d2)
Returns true if the d1 is greater than d2 and they are not equal.


isGreaterEqual

public static boolean isGreaterEqual(double d1,
                                     double d2)
Returns true if the d1 is greater than d1 or both are equal, or if one of the values is NaN


isLess

public static boolean isLess(double d1,
                             double d2)
Returns true if the d1 is less than d2 and they are not equal.


isLessEqual

public static boolean isLessEqual(double d1,
                                  double d2)
Returns true if the d1 is less than d1 or both are equal.


getLineSeparator

public static java.lang.String getLineSeparator()
Returns the correct line separator for the current operating system.


getLineSeparators

public static java.lang.String getLineSeparators(int number)
Returns the correct line separator for the current operating system concatenated for the given number of times.


transformAllLineSeparators

public static java.lang.String transformAllLineSeparators(java.lang.String text)
Replaces all possible line feed character combinations by "\n". This might be important for GUI purposes like tool tip texts which do not support carriage return combinations.


removeAllLineSeparators

public static java.lang.String removeAllLineSeparators(java.lang.String text)
Removes all possible line feed character combinations. This might be important for GUI purposes like tool tip texts which do not support carriage return combinations.


classNameWOPackage

public static java.lang.String classNameWOPackage(java.lang.Class c)
Returns the class name of the given class without the package information.


readOutput

public static java.lang.String readOutput(java.io.BufferedReader in)
                                   throws java.io.IOException
Reads the output of the reader and delivers it as string.

Throws:
java.io.IOException

getFile

public static java.io.File getFile(java.io.File parent,
                                   java.lang.String name)
Creates a file relative to the given parent if name is not an absolute file name. Returns null if name is null.


getReader

public static java.io.BufferedReader getReader(java.io.File file,
                                               java.nio.charset.Charset encoding)
                                        throws java.io.IOException
This method checks if the given file is a Zip file containing one entry (in case of file extension .zip). If this is the case, a reader based on a ZipInputStream for this entry is returned. Otherwise, this method checks if the file has the extension .gz. If this applies, a gzipped stream reader is returned. Otherwise, this method just returns a BufferedReader for the given file (file was not zipped at all).

Throws:
java.io.IOException

getDefaultEncoding

public static java.nio.charset.Charset getDefaultEncoding()
This method tries to identify the encoding if a GUI is running and a process is defined. In this case, the encoding is taken from the process. Otherwise, the method tries to identify the encoding via the property RapidMiner.PROPERTY_RAPIDMINER_GENERAL_DEFAULT_ENCODING. If this is not possible, this method just returns the default system encoding.


getRelativePath

public static java.lang.String getRelativePath(java.io.File firstFile,
                                               java.io.File secondFile)
                                        throws java.io.IOException
Returns the relative path of the first file resolved against the second.

Throws:
java.io.IOException

waitForProcess

public static void waitForProcess(Operator operator,
                                  java.lang.Process process,
                                  java.lang.String name)
                           throws OperatorException
Waits for process to die and writes log messages. Terminates if exit value is not 0.

Throws:
OperatorException

sendEmail

public static void sendEmail(java.lang.String address,
                             java.lang.String subject,
                             java.lang.String content)
Sends a mail to the given address, using the specified subject and contents. Subject must contain no whitespace!


addResourceSource

public static void addResourceSource(ResourceSource source)
Adds a new resource source. Might be used by plugins etc.


prependResourceSource

public static void prependResourceSource(ResourceSource source)
Adds a new resource source before the others. Might be used by plugins etc.


getResource

public static java.net.URL getResource(java.lang.ClassLoader loader,
                                       java.lang.String name)

getResource

public static java.net.URL getResource(java.lang.ClassLoader loader,
                                       java.lang.String prefix,
                                       java.lang.String name)

getResource

public static java.net.URL getResource(java.lang.String name)
Returns the desired resource. Tries first to find a resource in the core RapidMiner resources directory. If no resource with the given name is found, it is tried to load with help of the ResourceSource which might have been added by plugins. Please note that resource names are only allowed to use '/' as separator instead of File.separator!


readTextFile

public static java.lang.String readTextFile(java.io.File file)
                                     throws java.io.IOException
Throws:
java.io.IOException

readTextFile

public static java.lang.String readTextFile(java.io.Reader r)
                                     throws java.io.IOException
Throws:
java.io.IOException

booleanValue

public static boolean booleanValue(java.lang.String string,
                                   boolean deflt)

findSourceFile

public static java.io.File findSourceFile(java.lang.StackTraceElement e)

launchFileEditor

public static java.lang.Process launchFileEditor(java.io.File file,
                                                 int line)
                                          throws java.io.IOException
Throws:
java.io.IOException

escapeXML

public static java.lang.String escapeXML(java.lang.String string)
Replaces angle brackets by html entities.


findImplementationsInJar

public static void findImplementationsInJar(java.util.jar.JarFile jar,
                                            java.lang.Class superClass,
                                            java.util.List<java.lang.String> implementations)

findImplementationsInJar

public static void findImplementationsInJar(java.lang.ClassLoader loader,
                                            java.util.jar.JarFile jar,
                                            java.lang.Class<?> superClass,
                                            java.util.List<java.lang.String> implementations)

classForName

public static java.lang.Class classForName(java.lang.String className)
                                    throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

quotedSplit

public static java.lang.String[] quotedSplit(java.lang.String line,
                                             java.util.regex.Pattern separatorPattern)
Splits the given line according to the given separator pattern while only those separators will be regarded not lying inside of a quoting string. Please note that quoting characters will not be regarded if they are escaped by an escaping character. The usual double quote (") is used for quoting and can be escaped by a backslash, i.e. \".


quotedSplit

public static java.lang.String[] quotedSplit(java.lang.String line,
                                             java.util.regex.Pattern separatorPattern,
                                             char quotingChar,
                                             char escapeChar)
Splits the given line according to the given separator pattern while only those separators will be regarded not lying inside of a quoting string. Please note that quoting characters will not be regarded if they are escaped by an escaping character.


mergeQuotedSplits

@Deprecated
public static java.lang.String[] mergeQuotedSplits(java.lang.String line,
                                                              java.lang.String[] splittedTokens,
                                                              java.lang.String quoteString)
                                            throws java.io.IOException
Deprecated. Please use quotedSplit(String, Pattern, char, char) or quotedSplit(String, Pattern) instead

This method merges quoted splits, e.g. if a string line should be splitted by comma and commas inside of a quoted string should not be used as splitting point.

Parameters:
line - the original line
splittedTokens - the tokens as they were originally splitted
quoteString - the string which should be used as quote indicator, e.g. " or '
Returns:
the array of strings where the given quoteString was regarded
Throws:
java.io.IOException - if an open quote was not ended

getFirstToken

public static void getFirstToken(java.io.StreamTokenizer tokenizer)
                          throws java.io.IOException
Delivers the next token and skip empty lines.

Throws:
java.io.IOException

getLastToken

public static void getLastToken(java.io.StreamTokenizer tokenizer,
                                boolean endOfFileOk)
                         throws java.io.IOException
Delivers the next token and checks if its the end of line.

Throws:
java.io.IOException

getNextToken

public static void getNextToken(java.io.StreamTokenizer tokenizer)
                         throws java.io.IOException
Delivers the next token and checks for an unexpected end of line or file.

Throws:
java.io.IOException

waitForEOL

public static void waitForEOL(java.io.StreamTokenizer tokenizer)
                       throws java.io.IOException
Skips all tokens before next end of line (EOL).

Throws:
java.io.IOException

delete

public static void delete(java.io.File file)

copy

public static void copy(java.io.File srcPath,
                        java.io.File dstPath)
                 throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2001-2009 by Rapid-I