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 Details

  • Constructor Details

    • Util

      public Util()
      Empty default constructor.
  • Method Details

    • removeSubString

      public static String removeSubString​(String string, String subString)
      Removes characters from a string.
      Parameters:
      string - the string of interest
      subString - the sub-string to remove
      Returns:
      a version without forbidden characters
    • sendGAUpdate

      public static boolean sendGAUpdate​(String ua, String action, String label)
      Function for sending event requests to Google analytics.
      Parameters:
      ua - tracking ID
      action - the action
      label - the label
      Returns:
      true if the update was successful
    • getVersion

      public static String getVersion()
      Retrieves the version number set in the pom file.
      Returns:
      the version number of compomics-utilities
    • removeCharacters

      public static String removeCharacters​(String string, char forbiddenCharacter)
      Removes characters from a string.
      Parameters:
      string - the string of interest
      forbiddenCharacter - the character to remove
      Returns:
      a version without forbidden characters
    • removeCharacters

      public static String removeCharacters​(String string, String[] forbiddenCharacters)
      Removes characters from a string.
      Parameters:
      string - the string of interest
      forbiddenCharacters - the characters to remove
      Returns:
      a version without forbidden characters
    • removeForbiddenCharacters

      public static String removeForbiddenCharacters​(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​(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
    • replaceAll

      public static String replaceAll​(String string, char a, char b)
      Replaces all characters equals to a by b in the given string.
      Parameters:
      string - the string
      a - a
      b - 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 of
      places - 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 of
      places - 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 mass
      massError - the mass error
      Returns:
      the mass error as a ppm value relative to the theoretical mass
    • color2Hex

      public static String color2Hex​(int colorRGB)
      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

      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
    • getColor

      public static Color getColor​(int colorRGB)
      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 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​(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 - if a problem occurs when writing to the file
    • sameLists

      public static boolean sameLists​(ArrayList<?> list1, ArrayList<?> list2)
      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 list
      list2 - the second list
      Returns:
      a boolean indicating whether list1 has the same content as list2
    • getOccurrence

      public static int getOccurrence​(String input, char character)
      Returns the occurrence of a character in a string.
      Parameters:
      input - the string of interest
      character - the character to look for
      Returns:
      the occurrence of a character in a string
    • getIndexes

      public static ArrayList<Integer> getIndexes​(String bigString, String smallString)
      Returns at which indexes a small string can be found in a big string.
      Parameters:
      bigString - the big string
      smallString - the small string
      Returns:
      a list of the indexes where the small string can be found in the big string
    • readDoubleAsString

      public static double readDoubleAsString​(String doubleAsString) throws NumberFormatException
      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

      public static int convertBooleanToInteger​(Boolean booleanToConvert)
      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

      public static String keyValueToString​(String key, String value)
      Returns a string in the form key(value).
      Parameters:
      key - the key
      value - the value
      Returns:
      a string in the form value(attribute)