Package ffx.utilities

Class StringUtils

java.lang.Object
ffx.utilities.StringUtils

public class StringUtils extends Object
StringUtils class.
Since:
1.0
Author:
Michael Schnieders
  • Field Details

    • STANDARD_WATER_NAME

      public static final String STANDARD_WATER_NAME
      Constant STANDARD_WATER_NAME="HOH"
      See Also:
  • Method Details

    • cifForID

      public static String cifForID(String id)
      cifForID
      Parameters:
      id - a String object.
      Returns:
      a String object.
    • consecutiveInts

      public static List<int[]> consecutiveInts(int[] set)
      Finds consecutive subranges in an array of ints, and returns their mins and maxes. This can include singletons.

      Example: [4, 5, 6, 1, 1, 2, 5, 6, 7] would become [4,6],[1,1],[1,2],[5,7]

      Parameters:
      set - Array of ints to split into consecutive subranges.
      Returns:
      Consecutive subrange mins, maxes
    • createGzipReader

      public static Reader createGzipReader(File file) throws IOException
      Creates a reader from a Gzip file to text.
      Parameters:
      file - Gzip file to read from.
      Returns:
      A Reader.
      Throws:
      IOException - Thrown if creation of the GZip Reader fails.
    • createGzipReader

      public static Reader createGzipReader(File file, Charset cs) throws IOException
      Creates a reader from a Gzip file to text.
      Parameters:
      file - Gzip file to read from.
      cs - Character set to use.
      Returns:
      A Reader.
      Throws:
      IOException - Thrown if creation of the GZip Reader fails.
    • createGzipWriter

      public static Writer createGzipWriter(File file) throws IOException
      Creates a writer for text to a Gzip file.
      Parameters:
      file - Gzip file to write to.
      Returns:
      A Writer
      Throws:
      IOException - Thrown if creation of the GZip Writer fails.
    • createGzipWriter

      public static Writer createGzipWriter(File file, Charset cs) throws IOException
      Creates a writer for text to a Gzip file.
      Parameters:
      file - Gzip file to write to.
      cs - Character set to use.
      Returns:
      A Writer
      Throws:
      IOException - Thrown if creation of the GZip Writer fails.
    • fwDec

      public static String fwDec(double val, int width, int prec) throws IllegalArgumentException
      Prints a fixed-width decimal, similar to String.format(%width.precf, val), but ensuring the resulting string is never longer than width. If the result ends in a period (such as 14.), the method leaves off the decimal. An exception is thrown if the value cannot be formatted in the specified width.
      Parameters:
      val - Value to print
      width - Width of field
      prec - Number of decimal places
      Returns:
      Formatted string
      Throws:
      IllegalArgumentException - if any.
    • fwFpDec

      public static String fwFpDec(double val, int width, int prec) throws IllegalArgumentException
      Prints a fixed-width decimal using String.format conventions, throwing an error if the value cannot be formatted within that space.
      Parameters:
      val - the value to print.
      width - the width of the field.
      prec - the number of decimal places.
      Returns:
      a String object.
      Throws:
      IllegalArgumentException - If the length of String is greater than the width.
    • fwFpTrunc

      public static String fwFpTrunc(double val, int width, int prec)
      Prints a fixed-width decimal using String.format conventions, reducing the value if necessary to fit within the width.
      Parameters:
      val - The value to print.
      width - The width of the field.
      prec - The number of decimal places.
      Returns:
      a String object.
    • getIonNames

      public static Map<String,String> getIonNames()
      Returns a Map from recognized ion names to standard ion names.
      Returns:
      Map from ion names to standardized ion names.
    • getWaterNames

      public static List<String> getWaterNames()
      Returns a List of recognized water names (defensive copy).
      Returns:
      List of water names.
    • looksLikeIon

      public static boolean looksLikeIon(String name)
      Checks if a String matches a known monoatomic ion name.
      Parameters:
      name - String to check.
      Returns:
      If it is the name of a monoatomic ion.
    • looksLikeWater

      public static boolean looksLikeWater(String name)
      Checks if a String matches a known water name.
      Parameters:
      name - String to check.
      Returns:
      If it is a water name.
    • padLeft

      public static String padLeft(String s, int n)
      padLeft
      Parameters:
      s - a String object.
      n - The number of spaces to pad.
      Returns:
      a String object.
    • padRight

      public static String padRight(String s, int n)
      padRight
      Parameters:
      s - a String object.
      n - The number of spaces to pad.
      Returns:
      a String object.
    • parseAtomRange

      public static List<Integer> parseAtomRange(String keyType, String atomRange, int nAtoms) throws IllegalArgumentException
      Parses a numerical argument for an atom-specific flag.

      Parses, checks validity, and then returns the appropriate range.

      Input should be 1-indexed (user end), output 0-indexed.

      Parameters:
      keyType - Type of key
      atomRange - Input string
      nAtoms - Number of atoms in the MolecularAssembly
      Returns:
      A List of selected atoms.
      Throws:
      IllegalArgumentException - if an invalid argument
    • parseAtomRanges

      public static List<Integer> parseAtomRanges(String keyType, String atomRanges, int nAtoms) throws IllegalArgumentException
      Parses a list of atom ranges for a per atom flag.

      Parses, checks validity, and then returns a list with the index of selected atoms.

      Input should be 1-indexed (user end) and the output 0-indexed.

      Parameters:
      keyType - Type of key
      atomRanges - Input string
      nAtoms - Number of atoms in the MolecularAssembly
      Returns:
      A List of selected atoms.
      Throws:
      IllegalArgumentException - if an invalid argument
    • pdbForID

      public static String pdbForID(String id)
      pdbForID
      Parameters:
      id - a String object.
      Returns:
      a String object.
    • tryParseIon

      public static String tryParseIon(String name)
      Checks if a String looks like a known ion. Returns either its standardized name, or null if it doesn't look like an ion.
      Parameters:
      name - String to check.
      Returns:
      Standard ion name (matches) or null (no match).
    • tryParseWater

      public static String tryParseWater(String name)
      Checks if a String looks like a water molecule. Returns either a standardized water name, or null if it doesn't look like water.
      Parameters:
      name - String to check.
      Returns:
      Standard water name (matches) or null (no match).
    • writeAtomRanges

      public static String writeAtomRanges(int[] atoms)
      Write atoms ranges for a list of atom indices.
      Parameters:
      atoms - Atoms indices for which a comma separated list is desired.
      Returns:
      String of the atom list (comma separated, hyphens for large ranges).