public class Util extends Object
Modifier and Type | Field and Description |
---|---|
static String[] |
forbiddenCharacters
Forbidden characters in file names.
|
static String |
separator
Separator which can be used to separate things.
|
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static String |
appendSuffix(String fileName,
String suffix)
Appends a suffix to a file name before the file extension.
|
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 double |
floorDouble(double d,
int places)
Floors a double value to the wanted number of decimal places.
|
static String |
getExtension(File file)
Returns the extensions of a file.
|
static String |
getFileName(File file)
An OS independent getName alternative.
|
static String |
getFileName(String filePath)
An OS independent getName alternative.
|
static ArrayList<Integer> |
getIndexes(String bigString,
String smallString)
Returns at which indexes a small string can be found in a big string.
|
static int |
getNumberOfLines(File file)
Returns the number of lines in the given file.
|
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 File |
getUserSelectedFile(Component parent,
String[] fileEndings,
String[] fileFormatDescriptions,
String aDialogTitle,
String lastSelectedFolder,
boolean openDialog,
boolean formatSelectedByUser)
Returns the file selected by the user, or null if no file was selected.
|
static File |
getUserSelectedFile(Component parent,
String aFileEnding,
String aFileFormatDescription,
String aDialogTitle,
String lastSelectedFolder,
boolean openDialog)
Returns the file selected by the user, or null if no file was selected.
|
static File |
getUserSelectedFolder(Component parent,
String aDialogTitle,
String lastSelectedFolder,
String aFolderDescription,
String approveButtonText,
boolean openDialog)
Returns the folder selected by the user, or null if no folder was
selected.
|
static double |
readDoubleAsString(String doubleAsString)
Method for reading a double value as a string which uses either "," or
"." as the decimal symbol.
|
static String |
removeExtension(String fileName)
Removes the extension from a file name or path.
|
static String |
removeForbiddenCharacters(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(ArrayList list1,
ArrayList list2)
Convenience methods indicating whether the content of two lists have the
same content.
|
static boolean |
sameListsFirstListSorted(ArrayList list1,
ArrayList list2)
Convenience methods indicating whether the content of two lists have the
same content.
|
static boolean |
sameSets(HashSet set1,
HashSet set2)
Convenience methods indicating whether the content of two sets have the
same content.
|
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.
|
public static final String[] forbiddenCharacters
public static final String separator
public static String removeForbiddenCharacters(String string)
string
- the string of interestpublic static boolean containsForbiddenCharacter(String string)
string
- the string of interestpublic static double roundDouble(double d, int places)
d
- the double to round ofplaces
- number of decimal places wantedpublic static double floorDouble(double d, int places)
d
- the double to floor ofplaces
- number of decimal places wantedpublic static boolean deleteDir(File dir)
dir
- the directory to deletepublic static double getPpmError(double theoreticalMzValue, double massError)
theoreticalMzValue
- the theoretical massmassError
- the mass errorpublic static String color2Hex(Color color)
color
- the color to convertpublic static String getFileName(String filePath)
filePath
- the file path as a stringpublic static String getFileName(File file)
file
- the filepublic static String getExtension(File file)
file
- the filepublic static String appendSuffix(String fileName, String suffix)
fileName
- the file namesuffix
- the suffix to addpublic static String removeExtension(String fileName)
fileName
- the file namepublic static File getUserSelectedFile(Component parent, String aFileEnding, String aFileFormatDescription, String aDialogTitle, String lastSelectedFolder, boolean openDialog)
parent
- the parent dialog or frameaFileEnding
- the file type, e.g., .txtaFileFormatDescription
- the file format description, e.g., (Mascot
Generic Format) *.mgfaDialogTitle
- the title for the dialoglastSelectedFolder
- the last selected folderopenDialog
- if true an open dialog is shown, false results in a
save dialogpublic static File getUserSelectedFile(Component parent, String[] fileEndings, String[] fileFormatDescriptions, String aDialogTitle, String lastSelectedFolder, boolean openDialog, boolean formatSelectedByUser)
parent
- the parent dialog or framefileEndings
- the file types, e.g., .txtfileFormatDescriptions
- the file format description, e.g., (Mascot
Generic Format) *.mgfaDialogTitle
- the title for the dialoglastSelectedFolder
- the last selected folderopenDialog
- if true an open dialog is shown, false results in a
save dialogformatSelectedByUser
- if true the user will have to select the
format by himself, otherwise all formats will be availablepublic static File getUserSelectedFolder(Component parent, String aDialogTitle, String lastSelectedFolder, String aFolderDescription, String approveButtonText, boolean openDialog)
parent
- the parent dialog or frameaDialogTitle
- the title for the dialoglastSelectedFolder
- the last selected folderaFolderDescription
- the folder description, e.g., CPS FolderapproveButtonText
- the text on the approve buttonopenDialog
- if true the folder has to exist, if false the user will
be asked if he/she wants to create the folder is missingpublic static String tableToText(JTable table, String separator, ProgressDialogX progressDialog, boolean removeHtml)
table
- the table to turn in to textseparator
- the text separatorprogressDialog
- the progress dialogremoveHtml
- if true, HTML is converted to textpublic static void tableToFile(JTable table, String separator, ProgressDialogX progressDialog, boolean removeHtml, BufferedWriter writer) throws IOException
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 writtenIOException
- if a problem occurs when writing to the filepublic static void copyFile(File in, File out) throws IOException
in
- the file to copy fromout
- the file to copy toIOException
- if a problem occurs when writing to the filepublic static int getNumberOfLines(File file) throws IOException
file
- the file to find the number of lines inIOException
- if a problem occurs when writing to the filepublic static boolean sameLists(ArrayList list1, ArrayList list2)
list1
- the first listlist2
- the second listpublic static boolean sameSets(HashSet set1, HashSet set2)
set1
- the first setset2
- the second setpublic static boolean sameListsFirstListSorted(ArrayList list1, ArrayList list2)
list1
- the first listlist2
- the second listpublic static int getOccurrence(String input, char character)
input
- the string of interestcharacter
- the character to look forpublic static ArrayList<Integer> getIndexes(String bigString, String smallString)
bigString
- the big stringsmallString
- the small stringpublic static double readDoubleAsString(String doubleAsString) throws NumberFormatException
doubleAsString
- the double value as a stringNumberFormatException
- thrown if the double cannot be read as a
doubleCopyright © 2015. All rights reserved.