Package org.faktorips.util
Class StringUtil
java.lang.Object
org.faktorips.util.StringUtil
A collection of utility methods for Strings.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcamelCaseToUnderscore(String text) Returns a String where an occurrence of a character followed by an upper case character is replaced by these characters divided by an underscore.static StringcamelCaseToUnderscore(String text, boolean splitUppercaseSequences) Returns a String where an occurrence of a character followed by an upper case character is replaced by these characters divided by an underscore.static booleancontainsWhitespace(String string) Checks whether theStringcontains whitespace.static StringgetFileExtension(String fileName) static StringgetFilenameWithoutExtension(String filename) Returns the filename without extension.static InputStreamgetInputStreamForString(String data, String charset) Returns the input stream to read the given data.static final StringgetPackageName(String qualifiedClassName) Returns the package name for a given class name.static StringgetRangeString(int minValue, int maxValue) Returns a String of the form ' [x..y]', where x and y are the minimum and maximum values of a range.static StringgetRangeString(int minValue, int maxValue, int defaultValue) Returns a String of the form ' [x..y, z]', where x and y are the minimum and maximum values of a range, and z is the default value of that range.static final StringreadFromInputStream(InputStream is, String charsetName) Reads the available bytes from the input stream and returns them as a string using the givencharset.static final StringreadFromInputStream(InputStream is, Charset charset) Reads the available bytes from the input stream and returns them as a string using the givencharset.static StringtoCamelCase(String text, boolean firstUp) static final StringunqualifiedName(String qualifiedName) Takes a name like a class name and removes the package information from the beginning.
-
Field Details
-
BLANK
- See Also:
-
CAMEL_CASE_SEPERATORS
- See Also:
-
CHARSET_UTF8
- See Also:
-
CHARSET_ISO_8859_1
- See Also:
-
-
Method Details
-
readFromInputStream
Reads the available bytes from the input stream and returns them as a string using the givencharset.This method closes the input stream before returning!
- Throws:
IOException
-
readFromInputStream
public static final String readFromInputStream(InputStream is, String charsetName) throws IOException Reads the available bytes from the input stream and returns them as a string using the givencharset.This method closes the input stream before returning!
- Throws:
IOException
-
unqualifiedName
Takes a name like a class name and removes the package information from the beginning. -
getPackageName
Returns the package name for a given class name. Returns an empty String if the class name does not contain a package name.- Throws:
NullPointerException- if the qualifiedClassName is null.
-
getFilenameWithoutExtension
Returns the filename without extension. -
getFileExtension
-
getInputStreamForString
public static InputStream getInputStreamForString(String data, String charset) throws UnsupportedEncodingException Returns the input stream to read the given data.- Parameters:
data- The data to read.charset- The char set to be used to convert the string data to bytes.- Throws:
UnsupportedEncodingException- if the given char set is unsupported.
-
toCamelCase
-
camelCaseToUnderscore
Returns a String where an occurrence of a character followed by an upper case character is replaced by these characters divided by an underscore. Consecutive sequences of comma, dot, hyphen and whitespace is also replaced by one single underscore.For example:
CamelCase → Camel_Case a.,- b-cdEF → a_b_cd_EF
-
camelCaseToUnderscore
Returns a String where an occurrence of a character followed by an upper case character is replaced by these characters divided by an underscore. Consecutive sequences of comma, dot, hyphen and whitespace is also replaced by one single underscore.For example:
CamelCase → Camel_Case a.,- b-cdEF → a_b_cd_E_F (splitUppercaseSequences = true) a.,- b-cdEF → a_b_cd_EF (splitUppercaseSequences = false)
-
getRangeString
Returns a String of the form ' [x..y]', where x and y are the minimum and maximum values of a range. Note that maxValue will be represented as an asterisk (*) if its value is Integer.MAX_VALUE.- Parameters:
minValue- minimum value of the range.maxValue- maximum value of the range or Integer.MAX_VALUE to indicate an unbound range.- Returns:
- a String representation of the range in the form ' [min..max]'.
-
getRangeString
Returns a String of the form ' [x..y, z]', where x and y are the minimum and maximum values of a range, and z is the default value of that range. Note that maxValue will be represented as an asterisk (*) if its value is Integer.MAX_VALUE.- Parameters:
minValue- minimum value of the range.maxValue- maximum value of the range or Integer.MAX_VALUE to indicate an unbound range.defaultValue- default value of the range (if showDefault is false, this value will be ignored).- Returns:
- a String representation of the range in the form ' [min..max, default]'.
-
containsWhitespace
Checks whether theStringcontains whitespace.- Parameters:
string-Stringto be checked- Returns:
trueif thestringcontainswhitespace,falseif not
-