Package com.compomics.util
Class Util
java.lang.Object
com.compomics.util.Util
Includes general help methods that are used by the other classes.
- Author:
- Harald Barsnes, Marc Vaudel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault column separator for text files.static final StringDefault encoding, cf the second rule.static final String[]Forbidden characters in file names.static final StringThe line separator.static final doubleThe mass added per amino acid as part of the reference mass when converting a tolerance in Dalton to ppm. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcolor2Hex(int colorRGB) Converts a color to hex format for use in HTML tags.static StringConverts a color to hex format for use in HTML tags.static booleancontainsForbiddenCharacter(String string) Indicates whether a string contains characters forbidden in file names.static intconvertBooleanToInteger(Boolean booleanToConvert) Converts a boolean value to the corresponding integer value, 0 for false and 1 for true.static doublefloorDouble(double d, int places) Floors a double value to the wanted number of decimal places.static ColorgetColor(int colorRGB) Returns the color object corresponding to the given RGB representation.getIndexes(String bigString, String smallString) Returns at which indexes a small string can be found in a big string.static intgetOccurrence(String input, char character) Returns the occurrence of a character in a string.static doublegetPpmError(double theoreticalMzValue, double massError) Returns the ppm value of the given mass error relative to its theoretical m/z value.static StringRetrieves the version number set in the pom file.static StringkeyValueToString(String key, String value) Returns a string in the form key(value).static doublereadDoubleAsString(String doubleAsString) Method for reading a double value as a string which uses either "," or "." as the decimal symbol.static StringremoveCharacters(String string, char forbiddenCharacter) Removes characters from a string.static StringremoveCharacters(String string, String[] forbiddenCharacters) Removes characters from a string.static StringremoveForbiddenCharacters(String string) Removes the forbidden characters from a string.static StringremoveSubString(String string, String subString) Removes characters from a string.static StringreplaceAll(String string, char a, char b) Replaces all characters equals to a by b in the given string.static doubleroundDouble(double d, int places) Rounds a double value to the wanted number of decimal places.static booleanConvenience methods indicating whether the content of two lists have the same content.static booleansendGAUpdate(String ua, String action, String label) Function for sending event requests to Google analytics.static voidtableToFile(JTable table, String separator, ProgressDialogX progressDialog, boolean removeHtml, BufferedWriter writer) Writes the table to a file as separated text.static StringtableToText(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:
-
DEFAULT_COLUMN_SEPARATOR
Default column separator for text files.- See Also:
-
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:
-
-
Constructor Details
-
Util
public Util()
-
-
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 RGBs 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 IOException Writes 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)
-