Package ffx.utilities
Class StringUtils
java.lang.Object
ffx.utilities.StringUtils
StringUtils class.
- Since:
- 1.0
- Author:
- Michael Schnieders
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
cifForIDstatic List
<int[]> consecutiveInts
(int[] set) Finds consecutive subranges in an array of ints, and returns their mins and maxes.static Reader
createGzipReader
(File file) Creates a reader from a Gzip file to text.static Reader
createGzipReader
(File file, Charset cs) Creates a reader from a Gzip file to text.static Writer
createGzipWriter
(File file) Creates a writer for text to a Gzip file.static Writer
createGzipWriter
(File file, Charset cs) Creates a writer for text to a Gzip file.static String
fwDec
(double val, int width, int prec) Prints a fixed-width decimal, similar to String.format(%width.precf, val), but ensuring the resulting string is never longer than width.static String
fwFpDec
(double val, int width, int prec) Prints a fixed-width decimal usingString.format
conventions, throwing an error if the value cannot be formatted within that space.static String
fwFpTrunc
(double val, int width, int prec) Prints a fixed-width decimal usingString.format
conventions, reducing the value if necessary to fit within the width.Returns a Map from recognized ion names to standard ion names.Returns a List of recognized water names (defensive copy).static boolean
looksLikeIon
(String name) Checks if a String matches a known monoatomic ion name.static boolean
looksLikeWater
(String name) Checks if a String matches a known water name.static String
padLeftstatic String
padRightparseAtomRange
(String keyType, String atomRange, int nAtoms) Parses a numerical argument for an atom-specific flag.parseAtomRanges
(String keyType, String atomRanges, int nAtoms) Parses a list of atom ranges for a per atom flag.static String
pdbForIDstatic String
tryParseIon
(String name) Checks if a String looks like a known ion.static String
tryParseWater
(String name) Checks if a String looks like a water molecule.static String
writeAtomRanges
(int[] atoms) Write atoms ranges for a list of atom indices.
-
Field Details
-
STANDARD_WATER_NAME
ConstantSTANDARD_WATER_NAME="HOH"
- See Also:
-
-
Method Details
-
cifForID
cifForID -
consecutiveInts
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
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
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
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
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
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 printwidth
- Width of fieldprec
- Number of decimal places- Returns:
- Formatted string
- Throws:
IllegalArgumentException
- if any.
-
fwFpDec
Prints a fixed-width decimal usingString.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
Prints a fixed-width decimal usingString.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
Returns a Map from recognized ion names to standard ion names.- Returns:
- Map from ion names to standardized ion names.
-
getWaterNames
Returns a List of recognized water names (defensive copy).- Returns:
- List of water names.
-
looksLikeIon
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
Checks if a String matches a known water name.- Parameters:
name
- String to check.- Returns:
- If it is a water name.
-
padLeft
padLeft -
padRight
padRight -
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 keyatomRange
- Input stringnAtoms
- 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 keyatomRanges
- Input stringnAtoms
- Number of atoms in the MolecularAssembly- Returns:
- A List of selected atoms.
- Throws:
IllegalArgumentException
- if an invalid argument
-
pdbForID
pdbForID -
tryParseIon
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
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
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).
-