Package com.compomics.util
Class Util
java.lang.Object
com.compomics.util.Util
public class Util extends Object
Includes general help methods that are used by the other classes.
- Author:
- Harald Barsnes, Marc Vaudel
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_COLUMN_SEPARATOR
Default column separator for text files.static String
ENCODING
Default encoding, cf the second rule.static String[]
FORBIDDEN_CHARACTERS
Forbidden characters in file names.static String
LINE_SEPARATOR
The line separator.static double
MASS_PER_AA
The mass added per amino acid as part of the reference mass when converting a tolerance in Dalton to ppm. -
Constructor Summary
Constructors Constructor Description Util()
Empty default constructor. -
Method Summary
Modifier and Type Method Description static String
color2Hex(int colorRGB)
Converts a color to hex format for use in HTML tags.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 int
convertBooleanToInteger(Boolean booleanToConvert)
Converts a boolean value to the corresponding integer value, 0 for false and 1 for true.static double
floorDouble(double d, int places)
Floors a double value to the wanted number of decimal places.static Color
getColor(int colorRGB)
Returns the color object corresponding to the given rgb representation.static ArrayList<Integer>
getIndexes(String bigString, String smallString)
Returns at which indexes a small string can be found in a big string.static int
getOccurrence(String input, char character)
Returns the occurrence of a character in a string.static double
getPpmError(double theoreticalMzValue, double massError)
Returns the ppm value of the given mass error relative to its theoretical m/z value.static String
getVersion()
Retrieves the version number set in the pom file.static String
keyValueToString(String key, String value)
Returns a string in the form key(value).static double
readDoubleAsString(String doubleAsString)
Method for reading a double value as a string which uses either "," or "." as the decimal symbol.static String
removeCharacters(String string, char forbiddenCharacter)
Removes characters from a string.static String
removeCharacters(String string, String[] forbiddenCharacters)
Removes characters from a string.static String
removeForbiddenCharacters(String string)
Removes the forbidden characters from a string.static String
removeSubString(String string, String subString)
Removes characters from a string.static String
replaceAll(String string, char a, char b)
Replaces all characters equals to a by b in the given string.static double
roundDouble(double d, int places)
Rounds a double value to the wanted number of decimal places.static boolean
sameLists(ArrayList<?> list1, ArrayList<?> list2)
Convenience methods indicating whether the content of two lists have the same content.static boolean
sendGAUpdate(String ua, String action, String label)
Function for sending event requests to Google analytics.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.
-
Field Details
-
FORBIDDEN_CHARACTERS
Forbidden characters in file names. -
ENCODING
Default encoding, cf the second rule.- See Also:
- Constant Field Values
-
DEFAULT_COLUMN_SEPARATOR
Default column separator for text files.- See Also:
- Constant Field Values
-
LINE_SEPARATOR
The line separator. -
MASS_PER_AA
public static final double MASS_PER_AAThe mass added per amino acid as part of the reference mass when converting a tolerance in Dalton to ppm.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Util
public Util()Empty default constructor.
-
-
Method Details
-
removeSubString
Removes characters from a string.- Parameters:
string
- the string of interestsubString
- the sub-string to remove- Returns:
- a version without forbidden characters
-
sendGAUpdate
Function for sending event requests to Google analytics.- Parameters:
ua
- tracking IDaction
- the actionlabel
- the label- Returns:
- true if the update was successful
-
getVersion
Retrieves the version number set in the pom file.- Returns:
- the version number of compomics-utilities
-
removeCharacters
Removes characters from a string.- Parameters:
string
- the string of interestforbiddenCharacter
- the character to remove- Returns:
- a version without forbidden characters
-
removeCharacters
Removes characters from a string.- Parameters:
string
- the string of interestforbiddenCharacters
- the characters to remove- Returns:
- a version without forbidden characters
-
removeForbiddenCharacters
Removes the forbidden characters from a string.- Parameters:
string
- the string of interest- Returns:
- a version without forbidden characters
-
containsForbiddenCharacter
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
-
replaceAll
Replaces all characters equals to a by b in the given string.- Parameters:
string
- the stringa
- ab
- b- Returns:
- a string equal to string with a replaced by b
-
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 ofplaces
- number of decimal places wanted- Returns:
- double - the new double
-
floorDouble
public static double floorDouble(double d, int places)Floors a double value to the wanted number of decimal places.- Parameters:
d
- the double to floor ofplaces
- number of decimal places wanted- Returns:
- double - the new double
-
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 massmassError
- the mass error- Returns:
- the mass error as a ppm value relative to the theoretical mass
-
color2Hex
Converts a color to hex format for use in HTML tags.- Parameters:
colorRGB
- the color in rgb representation- Returns:
- the color in hex format
-
color2Hex
Converts a color to hex format for use in HTML tags.- Parameters:
color
- the color to convert- Returns:
- the color in hex format
-
getColor
Returns the color object corresponding to the given rgb representation.- Parameters:
colorRGB
- the color in rgb representation- Returns:
- the color object
-
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 textseparator
- the text separatorprogressDialog
- the progress dialogremoveHtml
- 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 IOExceptionWrites the table to a file as separated text.- Parameters:
table
- the table to write to fileseparator
- the text separatorprogressDialog
- the progress dialogremoveHtml
- if true, HTML is converted to textwriter
- the writer where the file is to be written- Throws:
IOException
- if a problem occurs when writing to the file
-
sameLists
Convenience methods indicating whether the content of two lists have the same content. Equality is based on the hash of the objects. Note that this method does not work for lists containing null;- Parameters:
list1
- the first listlist2
- the second list- Returns:
- a boolean indicating whether list1 has the same content as list2
-
getOccurrence
Returns the occurrence of a character in a string.- Parameters:
input
- the string of interestcharacter
- the character to look for- Returns:
- the occurrence of a character in a string
-
getIndexes
Returns at which indexes a small string can be found in a big string.- Parameters:
bigString
- the big stringsmallString
- the small string- Returns:
- a list of the indexes where the small string can be found in the big string
-
readDoubleAsString
Method for reading a double value as a string which uses either "," or "." as the decimal symbol.- Parameters:
doubleAsString
- the double value as a string- Returns:
- the double value
- Throws:
NumberFormatException
- thrown if the double cannot be read as a double
-
convertBooleanToInteger
Converts a boolean value to the corresponding integer value, 0 for false and 1 for true.- Parameters:
booleanToConvert
- the boolean value to convert- Returns:
- 0 for false and 1 for true
-
keyValueToString
Returns a string in the form key(value).- Parameters:
key
- the keyvalue
- the value- Returns:
- a string in the form value(attribute)
-