Class ReportStringUtil
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Constant for"false"
.static final String
a convenient shorthand to the line separator constant.static final char[]
Contains all chars that end a sentence in thetrimToSize(String, int, int, String)
method.static final String
a convenient shorthand for tabulations.static final String
Constant for"true"
. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
changeFileNameSuffixTo
(String filename, String suffix) Changes the filename suffix.static String
collectionAsString
(Collection<String> collection, String separator) Returns a string representation for the given collection using the given separator.static String
escapeHtml
(String source) Replaces occurrences of special control characters in the given input with a HTML representation.static String
escapeJavaScript
(String source) Escapes a String so it may be used in JavaScript String definitions.static String
escapePattern
(String source) Escapes a String so it may be used as a Perl5 regular expression.static String
formatRuntime
(long runtime) Formats a runtime in the format hh:mm:ss, to be used e.g.static boolean
Returnstrue
if the provided String is eithernull
or the empty String""
.static boolean
isEmptyOrWhitespaceOnly
(String value) Returnstrue
if the provided String is eithernull
or contains only white spaces.static boolean
Returnstrue
if the provided Objects are either bothnull
or equal according toObject.equals(Object)
.static boolean
isNotEmpty
(String value) Returnstrue
if the provided String is neithernull
nor the empty String""
.static boolean
isNotEmptyOrWhitespaceOnly
(String value) Returnstrue
if the provided String is neithernull
nor contains only white spaces.static int
lastIndexOf
(String source, char[] chars) Returns the last index of any of the given chars in the given source.static int
lastWhitespaceIn
(String source) Returns the last index a whitespace char the given source.static String
substitute
(String source, String searchString, String replaceString) SubstitutessearchString
in the given source String withreplaceString
.static String
Returns the java String literal for the given String.static String
trimToSize
(String source, int length) Returns a substring of the source, which is at most length characters long.static String
trimToSize
(String source, int length, int area, String suffix) Returns a substring of the source, which is at most length characters long, cut in the lastarea
chars in the source at a sentence ending char or whitespace.static String
trimToSize
(String source, int length, String suffix) Returns a substring of the source, which is at most length characters long.
-
Field Details
-
FALSE
Constant for"false"
. -
LINE_SEPARATOR
a convenient shorthand to the line separator constant. -
SENTENCE_ENDING_CHARS
public static final char[] SENTENCE_ENDING_CHARSContains all chars that end a sentence in thetrimToSize(String, int, int, String)
method. -
TABULATOR
a convenient shorthand for tabulations.- See Also:
-
TRUE
Constant for"true"
.
-
-
Method Details
-
changeFileNameSuffixTo
Changes the filename suffix.- Parameters:
filename
- the filename to be changedsuffix
- the new suffix of the file- Returns:
- the filename with the replaced suffix
-
collectionAsString
Returns a string representation for the given collection using the given separator.- Parameters:
collection
- the collection to printseparator
- the item separator- Returns:
- the string representation for the given collection
-
escapeHtml
Replaces occurrences of special control characters in the given input with a HTML representation.This method currently replaces line breaks to
<br/>
and special HTML chars like< > & "
with their HTML entity representation.- Parameters:
source
- the String to escape- Returns:
- the escaped String
-
escapeJavaScript
Escapes a String so it may be used in JavaScript String definitions.This method replaces line breaks, quotation marks and \ characters.
- Parameters:
source
- the String to escape- Returns:
- the escaped String
-
escapePattern
Escapes a String so it may be used as a Perl5 regular expression.This method replaces the following characters in a String:
{}[]()\$^.*+/
- Parameters:
source
- the string to escape- Returns:
- the escaped string
-
formatRuntime
Formats a runtime in the format hh:mm:ss, to be used e.g. in reports.If the runtime is greater then 24 hours, the format dd:hh:mm:ss is used.
- Parameters:
runtime
- the time to format- Returns:
- the formatted runtime
-
isEmpty
Returnstrue
if the provided String is eithernull
or the empty String""
.- Parameters:
value
- the value to check- Returns:
- true, if the provided value is null or the empty String, false otherwise
-
isEmptyOrWhitespaceOnly
Returnstrue
if the provided String is eithernull
or contains only white spaces.- Parameters:
value
- the value to check- Returns:
- true, if the provided value is null or contains only white spaces, false otherwise
-
isEqual
Returnstrue
if the provided Objects are either bothnull
or equal according toObject.equals(Object)
.- Parameters:
value1
- the first object to comparevalue2
- the second object to compare- Returns:
true
if the provided Objects are either bothnull
or equal according toObject.equals(Object)
-
isNotEmpty
Returnstrue
if the provided String is neithernull
nor the empty String""
.- Parameters:
value
- the value to check- Returns:
- true, if the provided value is not null and not the empty String, false otherwise
-
isNotEmptyOrWhitespaceOnly
Returnstrue
if the provided String is neithernull
nor contains only white spaces.- Parameters:
value
- the value to check- Returns:
true
, if the provided value isnull
or contains only white spaces,false
otherwise
-
lastIndexOf
Returns the last index of any of the given chars in the given source.If no char is found, -1 is returned.
- Parameters:
source
- the source to checkchars
- the chars to find- Returns:
- the last index of any of the given chars in the given source, or -1
-
lastWhitespaceIn
Returns the last index a whitespace char the given source.If no whitespace char is found, -1 is returned.
- Parameters:
source
- the source to check- Returns:
- the last index a whitespace char the given source, or -1
-
substitute
SubstitutessearchString
in the given source String withreplaceString
.This is a high-performance implementation which should be used as a replacement for
in case no regular expression evaluation is required.String.replaceAll(java.lang.String, java.lang.String)
- Parameters:
source
- the content which is scannedsearchString
- the String which is searched in contentreplaceString
- the String which replacessearchString
- Returns:
- the substituted String
-
toUnicodeLiteral
Returns the java String literal for the given String.This is the form of the String that had to be written into source code using the unicode escape sequence for special characters.
Example: "�" would be transformed to "\\u00C4".
- Parameters:
s
- a string that may contain non-ascii characters- Returns:
- the java unicode escaped string Literal of the given input string
-
trimToSize
Returns a substring of the source, which is at most length characters long.This is the same as calling
trimToSize(String, int, String)
with the parameters(source, length, " ...")
.- Parameters:
source
- the string to trimlength
- the maximum length of the string to be returned- Returns:
- a substring of the source, which is at most length characters long
-
trimToSize
Returns a substring of the source, which is at most length characters long.If a char is cut, the given
suffix
is appended to the result.This is almost the same as calling
trimToSize(String, int, int, String)
with the parameters(source, length, length*, suffix)
. Iflength
if larger then 100, thenlength* = length / 2
, otherwiselength* = length
.- Parameters:
source
- the string to trimlength
- the maximum length of the string to be returnedsuffix
- the suffix to append in case the String was trimmed- Returns:
- a substring of the source, which is at most length characters long
-
trimToSize
Returns a substring of the source, which is at most length characters long, cut in the lastarea
chars in the source at a sentence ending char or whitespace.If a char is cut, the given
suffix
is appended to the result.- Parameters:
source
- the string to trimlength
- the maximum length of the string to be returnedarea
- the area at the end of the string in which to find a sentence ender or whitespacesuffix
- the suffix to append in case the String was trimmed- Returns:
- a substring of the source, which is at most length characters long
-