com.compomics.util
Class Util

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

public class Util
extends java.lang.Object

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

Author:
Harald Barsnes, Marc Vaudel

Field Summary
static java.lang.String[] forbiddenCharacters
          Forbidden characters in file names.
 
Constructor Summary
Util()
           
 
Method Summary
static java.lang.String color2Hex(java.awt.Color color)
          Converts a color to hex format for use in HTML tags.
static boolean containsForbiddenCharacter(java.lang.String string)
          Indicates whether a string contains characters forbidden in file names.
static void copyFile(java.io.File in, java.io.File out)
          Copy the content of one file to another.
static boolean deleteDir(java.io.File dir)
          Deletes all files and subdirectories under dir.
static java.lang.String getExtension(java.io.File file)
          Returns the extensions of a file.
static java.lang.String getFileName(java.io.File file)
          An OS independent getName alternative.
static java.lang.String getFileName(java.lang.String filePath)
          An OS independent getName alternative.
static int getNumberOfLines(java.io.File file)
          Returns the number of lines in the given file.
static double getPpmError(double theoreticalMzValue, double massError)
          Returns the ppm value of the given mass error relative to its theoretical m/z value.
static java.io.File getUserSelectedFile(java.awt.Component parent, java.lang.String aFileEnding, java.lang.String aFileFormatDescription, java.lang.String aDialogTitle, java.lang.String lastSelectedFolder, boolean openDialog)
          Returns the file selected by the user, or null if no file was selected.
static java.lang.String removeExtension(java.lang.String fileName)
          Removes the extension from a file name or path.
static java.lang.String removeForbiddenCharacters(java.lang.String string)
          Removes the forbidden characters from a string
static double roundDouble(double d, int places)
          Rounds a double value to the wanted number of decimal places.
static boolean sameLists(java.util.ArrayList<java.lang.Integer> list1, java.util.ArrayList<java.lang.Integer> list2)
          Convenience methods indicating whether the content of two lists have the same content.
static void tableToFile(javax.swing.JTable table, java.lang.String separator, ProgressDialogX progressDialog, boolean removeHtml, java.io.BufferedWriter writer)
          Writes the table to a file as separated text.
static java.lang.String tableToText(javax.swing.JTable table, java.lang.String separator, ProgressDialogX progressDialog, 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 java.lang.String[] forbiddenCharacters
Forbidden characters in file names.

Constructor Detail

Util

public Util()
Method Detail

removeForbiddenCharacters

public static java.lang.String removeForbiddenCharacters(java.lang.String string)
Removes the forbidden characters from a string

Parameters:
string - the string of interest
Returns:
a version without forbidden characters

containsForbiddenCharacter

public static boolean containsForbiddenCharacter(java.lang.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(java.io.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 java.lang.String color2Hex(java.awt.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 java.lang.String getFileName(java.lang.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

getFileName

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

Parameters:
file - the file
Returns:
the file name, or the complete path of no file name is detected

getExtension

public static java.lang.String getExtension(java.io.File file)
Returns the extensions of a file.

Parameters:
file - the file
Returns:
the extension of a file

removeExtension

public static java.lang.String removeExtension(java.lang.String fileName)
Removes the extension from a file name or path.

Parameters:
fileName - the file name
Returns:
the file name without extension

getUserSelectedFile

public static java.io.File getUserSelectedFile(java.awt.Component parent,
                                               java.lang.String aFileEnding,
                                               java.lang.String aFileFormatDescription,
                                               java.lang.String aDialogTitle,
                                               java.lang.String lastSelectedFolder,
                                               boolean openDialog)
Returns the file selected by the user, or null if no file was selected. Note that the last selected folder value is not updated during this method, and the code calling this method therefore has to take care of this if wanted.

Parameters:
parent - the parent dialog or frame
aFileEnding - the file type, e.g., .txt
aFileFormatDescription - the file format description, e.g., (Mascot Generic Format) *.mgf
aDialogTitle - the title for the dialog
lastSelectedFolder - the last selected folder
openDialog - if true an open dialog is shown, false results in a save dialog
Returns:
the file selected by the user, or null if no file was selected

tableToText

public static java.lang.String tableToText(javax.swing.JTable table,
                                           java.lang.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

tableToFile

public static void tableToFile(javax.swing.JTable table,
                               java.lang.String separator,
                               ProgressDialogX progressDialog,
                               boolean removeHtml,
                               java.io.BufferedWriter writer)
                        throws java.io.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:
java.io.IOException

copyFile

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

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

getNumberOfLines

public static int getNumberOfLines(java.io.File file)
                            throws java.io.IOException
Returns the number of lines in the given file.

Parameters:
file - the file to find the number of lines in
Returns:
the number of lines in the given file
Throws:
java.io.IOException

sameLists

public static boolean sameLists(java.util.ArrayList<java.lang.Integer> list1,
                                java.util.ArrayList<java.lang.Integer> list2)
Convenience methods indicating whether the content of two lists have the same content.

Parameters:
list1 - the first list
list2 - the second list
Returns:
a boolean indicating whether list1 has the same content as list2


Copyright © 2013. All Rights Reserved.