Package org.biojava.nbio.core.util
Class StringManipulationHelper
- java.lang.Object
-
- org.biojava.nbio.core.util.StringManipulationHelper
-
public class StringManipulationHelper extends Object
A utility class for commonString
manipulation tasks. All functions are static methods.- Author:
- Amr ALHOSSARY, Richard Adams
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
convertStreamToString(InputStream stream)
Converts an InputStream of text to a String, closing the stream before returning.static boolean
equalsToIgnoreEndline(String expected, String actual)
Compares two strings in a case-sensitive manner for equality, line by line, ignoring any difference of end line delimiters contained within the 2 Strings.static boolean
equalsToXml(String expected, String actual)
This method is not implemented or used, never returns true and should probably be removed.static String
join(Collection<String> s, String delimiter)
Joins Strings together with a delimiter to a singlestatic String
padLeft(String s, int n)
Adds padding to left of supplied stringstatic String
padRight(String s, int n)
Adds padding to right of supplied string
-
-
-
Method Detail
-
convertStreamToString
public static String convertStreamToString(InputStream stream)
Converts an InputStream of text to a String, closing the stream before returning.- Newlines are converted to Unix newlines (\n)
- Default charset encoding is used to read the stream.
- Any IOException reading the stream is 'squashed' and not made available to caller
- An additional newline is appended at the end of the string.
- Parameters:
stream
-- Returns:
- a possibly empty but non-null String
-
equalsToIgnoreEndline
public static boolean equalsToIgnoreEndline(String expected, String actual)
Compares two strings in a case-sensitive manner for equality, line by line, ignoring any difference of end line delimiters contained within the 2 Strings.
This method should be used if and only if two Strings are considered identical when all nodes are identical including their relative order. Generally useful when asserting identity of automatically regenerated XML or PDB.- Parameters:
expected
-actual
-
-
equalsToXml
public static boolean equalsToXml(String expected, String actual)
This method is not implemented or used, never returns true and should probably be removed.- Parameters:
expected
-actual
-- Returns:
- Throws:
UnsupportedOperationException
- in most cases
-
padLeft
public static String padLeft(String s, int n)
Adds padding to left of supplied string- Parameters:
s
- The String to padn
- an integer >= 1- Returns:
- The left-padded string.
- Throws:
IllegalArgumentException
- if n <= 0
-
padRight
public static String padRight(String s, int n)
Adds padding to right of supplied string- Parameters:
s
- The String to padn
- an integer >= 1- Returns:
- The right-padded string.
- Throws:
IllegalArgumentException
- if n <= 0
-
-