Class StringUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
capitalize
(String str) Borrowed from commons-langStringUtils.capitalize()
method.static int
compareIgnoreCase
(String a, String b) Compare two strings, ignoring case.static int
compareWithCase
(String a, String b) Compare two strings, honoring case.static boolean
equalsIgnoreCase
(String a, String b) Test if two strings are equal, ignoring case.static String
formatWithSuffix
(long value) Formats an integral value as a decimal number with 'k', 'm', or 'g' suffix if it is an exact multiple of 1024, otherwise returns the value representation as a decimal number without suffix.static boolean
isEmptyOrNull
(String stringValue) Test if a string is empty or null.static String
join
(Collection<String> parts, String separator) Join a collection of Strings together using the specified separator.static String
join
(Collection<String> parts, String separator, String lastSeparator) Join a collection of Strings together using the specified separator and a lastSeparator which is used for joining the second last and the last part.static String
nameWithDotGit
(String name) AppendsConstants.DOT_GIT_EXT
unless the given name already ends with that suffix.static int
parseIntWithSuffix
(String value, boolean positiveOnly) Parses a number with optional case-insensitive suffix 'k', 'm', or 'g' indicating KiB, MiB, and GiB, respectively.static long
parseLongWithSuffix
(String value, boolean positiveOnly) Parses a number with optional case-insensitive suffix 'k', 'm', or 'g' indicating KiB, MiB, and GiB, respectively.static String
Replace CRLF, CR or LF with a single space.static boolean
Parse a string as a standard Git boolean value.static Boolean
toBooleanOrNull
(String stringValue) Parse a string as a standard Git boolean value.static char
toLowerCase
(char c) Convert the input to lowercase.static String
toLowerCase
(String in) Convert the input string to lower case, according to the "C" locale.
-
Field Details
-
KiB
private static final long KiB- See Also:
-
MiB
private static final long MiB- See Also:
-
GiB
private static final long GiB- See Also:
-
LC
private static final char[] LC
-
-
Constructor Details
-
StringUtils
private StringUtils()
-
-
Method Details
-
toLowerCase
public static char toLowerCase(char c) Convert the input to lowercase.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale. Only characters in the range 'A' through 'Z' are converted. All other characters are left as-is, even if they otherwise would have a lowercase character equivalent.
- Parameters:
c
- the input character.- Returns:
- lowercase version of the input.
-
toLowerCase
Convert the input string to lower case, according to the "C" locale.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale. Only characters in the range 'A' through 'Z' are converted, all other characters are left as-is, even if they otherwise would have a lowercase character equivalent.
- Parameters:
in
- the input string. Must not be null.- Returns:
- a copy of the input string, after converting characters in the range 'A'..'Z' to 'a'..'z'.
-
capitalize
Borrowed from commons-langStringUtils.capitalize()
method.Capitalizes a String changing the first letter to title case as per
Character.toTitleCase(char)
. No other letters are changed.A
null
input String returnsnull
.- Parameters:
str
- the String to capitalize, may be null- Returns:
- the capitalized String,
null
if null String input - Since:
- 4.0
-
equalsIgnoreCase
Test if two strings are equal, ignoring case.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.
- Parameters:
a
- first string to compare.b
- second string to compare.- Returns:
- true if a equals b
-
compareIgnoreCase
Compare two strings, ignoring case.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.
- Parameters:
a
- first string to compare.b
- second string to compare.- Returns:
- an int.
- Since:
- 2.0
-
compareWithCase
Compare two strings, honoring case.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.
- Parameters:
a
- first string to compare.b
- second string to compare.- Returns:
- an int.
- Since:
- 2.0
-
toBoolean
Parse a string as a standard Git boolean value. SeetoBooleanOrNull(String)
.- Parameters:
stringValue
- the string to parse.- Returns:
- the boolean interpretation of
value
. - Throws:
IllegalArgumentException
- ifvalue
is not recognized as one of the standard boolean names.
-
toBooleanOrNull
Parse a string as a standard Git boolean value.The terms
yes
,true
,1
,on
can all be used to meantrue
.The terms
no
,false
,0
,off
can all be used to meanfalse
.Comparisons ignore case, via
equalsIgnoreCase(String, String)
.- Parameters:
stringValue
- the string to parse.- Returns:
- the boolean interpretation of
value
or null in case the string does not represent a boolean value
-
join
Join a collection of Strings together using the specified separator.- Parameters:
parts
- Strings to joinseparator
- used to join- Returns:
- a String with all the joined parts
-
join
Join a collection of Strings together using the specified separator and a lastSeparator which is used for joining the second last and the last part.- Parameters:
parts
- Strings to joinseparator
- separator used to join all but the two last elementslastSeparator
- separator to use for joining the last two elements- Returns:
- a String with all the joined parts
-
nameWithDotGit
AppendsConstants.DOT_GIT_EXT
unless the given name already ends with that suffix.- Parameters:
name
- to complete- Returns:
- the name ending with
Constants.DOT_GIT_EXT
- Since:
- 6.1
-
isEmptyOrNull
Test if a string is empty or null.- Parameters:
stringValue
- the string to check- Returns:
true
if the string isnull
or empty
-
replaceLineBreaksWithSpace
Replace CRLF, CR or LF with a single space.- Parameters:
in
- A string with line breaks- Returns:
- in without line breaks
- Since:
- 3.1
-
parseLongWithSuffix
public static long parseLongWithSuffix(@NonNull String value, boolean positiveOnly) throws NumberFormatException, StringIndexOutOfBoundsException Parses a number with optional case-insensitive suffix 'k', 'm', or 'g' indicating KiB, MiB, and GiB, respectively. The suffix may follow the number with optional separation by one or more blanks.- Parameters:
value
-String
to parse; with leading and trailing whitespace ignoredpositiveOnly
-true
to only accept positive numbers,false
to allow negative numbers, too- Returns:
- the value parsed
- Throws:
NumberFormatException
- if the is not parseable, or beyond the range ofLong
StringIndexOutOfBoundsException
- if the string is empty or contains only whitespace, or contains only the letter 'k', 'm', or 'g'- Since:
- 6.0
-
parseIntWithSuffix
public static int parseIntWithSuffix(@NonNull String value, boolean positiveOnly) throws NumberFormatException, StringIndexOutOfBoundsException Parses a number with optional case-insensitive suffix 'k', 'm', or 'g' indicating KiB, MiB, and GiB, respectively. The suffix may follow the number with optional separation by blanks.- Parameters:
value
-String
to parse; with leading and trailing whitespace ignoredpositiveOnly
-true
to only accept positive numbers,false
to allow negative numbers, too- Returns:
- the value parsed
- Throws:
NumberFormatException
- if the is not parseable or beyond the range ofInteger
StringIndexOutOfBoundsException
- if the string is empty or contains only whitespace, or contains only the letter 'k', 'm', or 'g'- Since:
- 6.0
-
formatWithSuffix
Formats an integral value as a decimal number with 'k', 'm', or 'g' suffix if it is an exact multiple of 1024, otherwise returns the value representation as a decimal number without suffix.- Parameters:
value
- Value to format- Returns:
- the value's String representation
- Since:
- 6.0
-