com.compomics.util
Class Util

java.lang.Object
  extended by com.compomics.util.Util

public class Util
extends Object

Includes general help methods that are used by the other classes.

Author:
Harald Barsnes

Field Summary
static String[] forbiddenCharacters
          Forbidden characters in file names
 
Constructor Summary
Util()
           
 
Method Summary
static String color2Hex(Color color)
          Converts a color to hex format for use in HTML tags.
static boolean containsForbiddenCharacter(String string)
          Indicates whether a string contains characters forbidden in file names
static void copyFile(File in, File out)
          Copy the content of one file to another.
static boolean deleteDir(File dir)
          Deletes all files and subdirectories under dir.
static String getFileName(String filePath)
          An OS independent getName alternative.
static double getPpmError(double theoreticalMzValue, double massError)
          Returns the ppm value of the given mass error relative to its theoretical m/z value.
static double roundDouble(double d, int places)
          Rounds a double value to the wanted number of decimal places.
static void tableToFile(JTable table, String separator, ProgressDialogX progressDialog, boolean cancelProgress, boolean removeHtml, BufferedWriter writer)
          Writes the table to a file as separated text.
static void tableToFile(JTable table, String separator, ProgressDialogX progressDialog, boolean removeHtml, BufferedWriter writer)
          Writes the table to a file as separated text.
static String tableToText(JTable table, String separator, ProgressDialogX progressDialog, boolean removeHtml)
          Returns the table as a separated text file.
static String tableToText(JTable table, String separator, ProgressDialogX progressDialog, boolean cancelProgress, boolean removeHtml)
          Returns the table as a separated text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

forbiddenCharacters

public static final String[] forbiddenCharacters
Forbidden characters in file names

Constructor Detail

Util

public Util()
Method Detail

containsForbiddenCharacter

public static boolean containsForbiddenCharacter(String string)
Indicates whether a string contains characters forbidden in file names

Parameters:
string - the string of interest
Returns:
a boolean indicating whether a string contains characters forbidden in file names

roundDouble

public static double roundDouble(double d,
                                 int places)
Rounds a double value to the wanted number of decimal places.

Parameters:
d - the double to round of
places - number of decimal places wanted
Returns:
double - the new double

deleteDir

public static boolean deleteDir(File dir)
Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

Parameters:
dir -
Returns:
rue if all deletions were successful

getPpmError

public static double getPpmError(double theoreticalMzValue,
                                 double massError)
Returns the ppm value of the given mass error relative to its theoretical m/z value.

Parameters:
theoreticalMzValue - the theoretical mass
massError - the mass error
Returns:
the mass error as a ppm value relative to the theoretical mass

color2Hex

public static String color2Hex(Color color)
Converts a color to hex format for use in HTML tags.

Parameters:
color - the color to convert
Returns:
the color in hex format

getFileName

public static String getFileName(String filePath)
An OS independent getName alternative. Useful if the path is provided as a hardcoded string and opened in a different OS.

Parameters:
filePath - the file path as a string
Returns:
the file name, or the complete path of no file name is detected

tableToText

public static String tableToText(JTable table,
                                 String separator,
                                 ProgressDialogX progressDialog,
                                 boolean removeHtml)
Returns the table as a separated text file.

Parameters:
table - the table to turn in to text
separator - the text separator
progressDialog - the progress dialog
removeHtml - if true, html is converted to text
Returns:
the table as a separated text file

tableToText

public static String tableToText(JTable table,
                                 String separator,
                                 ProgressDialogX progressDialog,
                                 boolean cancelProgress,
                                 boolean removeHtml)
Returns the table as a separated text file.

Parameters:
table - the table to turn in to text
separator - the text separator
progressDialog - the progress dialog
cancelProgress - set to true to cancel the export
removeHtml - if true, html is converted to text
Returns:
the table as a separated text file

tableToFile

public static void tableToFile(JTable table,
                               String separator,
                               ProgressDialogX progressDialog,
                               boolean removeHtml,
                               BufferedWriter writer)
                        throws IOException
Writes the table to a file as separated text.

Parameters:
table - the table to write to file
separator - the text separator
progressDialog - the progress dialog
removeHtml - if true, html is converted to text
writer - the writer where the file is to be written
Throws:
IOException

tableToFile

public static void tableToFile(JTable table,
                               String separator,
                               ProgressDialogX progressDialog,
                               boolean cancelProgress,
                               boolean removeHtml,
                               BufferedWriter writer)
                        throws IOException
Writes the table to a file as separated text.

Parameters:
table - the table to write to file
separator - the text separator
progressDialog - the progress dialog
cancelProgress - set to true to cancel the export
removeHtml - if true, html is converted to text
writer - the writer where the file is to be written
Throws:
IOException

copyFile

public static void copyFile(File in,
                            File out)
                     throws IOException
Copy the content of one file to another.

Parameters:
in - the file to copy from
out - the file to copy to
Throws:
IOException


Copyright © 2012. All Rights Reserved.