public final class StringUtils
extends java.lang.Object
Operations on String
that are null
safe.
The StringUtils
class defines certain words related to
String handling.
null
""
)' '
, char 32)Character.isWhitespace(char)
String.trim()
StringUtils
handles null
input Strings quietly.
That is to say that a null
input will return null
.
Where a boolean
or int
is being returned
details vary by method.
A side effect of the null
handling is that a
NullPointerException
should be considered a bug in
StringUtils
.
This class's source was modified from the Apache commons-lang and Apache commons-text libraries: https://github.com/apache/commons-lang/, https://github.com/apache/commons-text/
#ThreadSafe#
String
,
Apache Commons Lang,
Apache Commons Text ,
Elephant bird licenseModifier and Type | Method and Description |
---|---|
static java.lang.String |
capitalize(java.lang.String str)
Capitalizes a String changing the first character to title case as
per
Character.toTitleCase(int) . |
static boolean |
equals(java.lang.String cs1,
java.lang.String cs2)
Compares two Strings, returning
true if they represent
equal sequences of characters. |
static java.lang.String |
escapeJavaString(java.lang.Object object,
java.lang.String indent) |
static boolean |
isBlank(java.lang.CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.
|
static boolean |
isEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is empty ("") or null.
|
static boolean |
isNotBlank(java.lang.CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
|
static java.lang.String |
leftPad(java.lang.String str,
int size)
Left pad a String with spaces (' ').
|
static java.lang.String |
leftPad(java.lang.String str,
int size,
char padChar)
Left pad a String with a specified character.
|
static java.lang.String |
leftPad(java.lang.String str,
int size,
java.lang.String padStr)
Left pad a String with a specified String.
|
static int |
levenshteinDistance(java.lang.CharSequence left,
java.lang.CharSequence right,
int threshold)
Find the Levenshtein distance between two CharSequences if it's less than or
equal to a given threshold.
|
static java.lang.String |
lowerCase(java.lang.String str)
Converts a String to lower case as per
String.toLowerCase() . |
static java.lang.String |
repeat(char ch,
int repeat)
Returns padding using the specified delimiter repeated
to a given length.
|
static java.lang.String |
repeat(java.lang.String str,
int repeat)
Repeat a String
repeat times to form a
new String. |
static java.lang.String |
rightPad(java.lang.String str,
int size)
Right pad a String with spaces (' ').
|
static java.lang.String |
rightPad(java.lang.String str,
int size,
char padChar)
Right pad a String with a specified character.
|
static java.lang.String |
rightPad(java.lang.String str,
int size,
java.lang.String padStr)
Right pad a String with a specified String.
|
static boolean |
startsWithIgnoreCase(java.lang.String str,
java.lang.String prefix)
Tests if this string starts with the specified prefix ignoring case considerations.
|
static java.lang.String |
strip(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the start and end of a String.
|
static java.lang.String |
stripEnd(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the end of a String.
|
static java.lang.String |
stripStart(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the start of a String.
|
static java.lang.String |
stripToEmpty(java.lang.String str)
Strips whitespace from the start and end of a String returning
an empty String if
null input. |
static java.lang.String |
substring(java.lang.String str,
int start)
Gets a substring from the specified String avoiding exceptions.
|
static java.lang.String |
substring(java.lang.String str,
int start,
int end)
Gets a substring from the specified String avoiding exceptions.
|
static java.lang.String |
trim(java.lang.String str)
Removes control characters (char <= 32) from both
ends of this String, handling
null by returning
null . |
static java.lang.String |
trimToEmpty(java.lang.String str)
Removes control characters (char <= 32) from both
ends of this String returning an empty String ("") if the String
is empty ("") after the trim or if it is
null . |
static java.lang.String |
trimToNull(java.lang.String str)
Removes control characters (char <= 32) from both
ends of this String returning
null if the String is
empty ("") after the trim or if it is null . |
static java.lang.String |
uncapitalize(java.lang.String str)
Uncapitalizes a String, changing the first character to lower case as
per
Character.toLowerCase(int) . |
static java.lang.String |
upperCase(java.lang.String str)
Converts a String to upper case as per
String.toUpperCase() . |
static java.lang.String |
wrap(java.lang.String str,
int wrapLength)
Wraps a single line of text, identifying words by
' ' . |
static java.lang.String |
wrap(java.lang.String str,
int wrapLength,
java.lang.String newLineStr,
boolean wrapLongWords)
Wraps a single line of text, identifying words by
' ' . |
static java.lang.String |
wrap(java.lang.String str,
int wrapLength,
java.lang.String newLineStr,
boolean wrapLongWords,
java.lang.String wrapOn)
Wraps a single line of text, identifying words by
wrapOn . |
public static boolean isEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is empty or nullpublic static boolean isBlank(java.lang.CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.
Whitespace is defined by Character.isWhitespace(char)
.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is null, empty or whitespace onlypublic static boolean isNotBlank(java.lang.CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
Whitespace is defined by Character.isWhitespace(char)
.
StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is not empty and not null and not whitespace onlypublic static java.lang.String trim(java.lang.String str)
Removes control characters (char <= 32) from both
ends of this String, handling null
by returning
null
.
The String is trimmed using String.trim()
.
Trim removes start and end characters <= 32.
StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"
str
- the String to be trimmed, may be nullnull
if null String inputpublic static java.lang.String trimToNull(java.lang.String str)
Removes control characters (char <= 32) from both
ends of this String returning null
if the String is
empty ("") after the trim or if it is null
.
The String is trimmed using String.trim()
.
Trim removes start and end characters <= 32.
StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc"
str
- the String to be trimmed, may be nullnull
if only chars <= 32, empty or null String inputpublic static java.lang.String trimToEmpty(java.lang.String str)
Removes control characters (char <= 32) from both
ends of this String returning an empty String ("") if the String
is empty ("") after the trim or if it is null
.
The String is trimmed using String.trim()
.
Trim removes start and end characters <= 32.
StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"
str
- the String to be trimmed, may be nullnull
inputpublic static boolean equals(java.lang.String cs1, java.lang.String cs2)
Compares two Strings, returning true
if they represent
equal sequences of characters.
null
s are handled without exceptions. Two null
references are considered to be equal. The comparison is case sensitive.
StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false
cs1
- the first String, may be null
cs2
- the second String, may be null
true
if the Strings are equal (case-sensitive), or both null
Object.equals(Object)
,
Sourcepublic static java.lang.String substring(java.lang.String str, int start)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start n
characters from the end of the String.
A null
String will return null
.
An empty ("") String will return "".
StringUtils.substring(null, *) = null StringUtils.substring("", *) = "" StringUtils.substring("abc", 0) = "abc" StringUtils.substring("abc", 2) = "c" StringUtils.substring("abc", 4) = "" StringUtils.substring("abc", -2) = "bc" StringUtils.substring("abc", -4) = "abc"
str
- the String to get the substring from, may be nullstart
- the position to start from, negative means count back from the end of the String by this many
charactersnull
if null String inputpublic static java.lang.String substring(java.lang.String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n
characters from the end of the String.
The returned substring starts with the character in the start
position and ends before the end
position. All position counting is
zero-based -- i.e., to start at the beginning of the string use
start = 0
. Negative start and end positions can be used to
specify offsets relative to the end of the String.
If start
is not strictly to the left of end
, ""
is returned.
StringUtils.substring(null, *, *) = null StringUtils.substring("", * , *) = ""; StringUtils.substring("abc", 0, 2) = "ab" StringUtils.substring("abc", 2, 0) = "" StringUtils.substring("abc", 2, 4) = "c" StringUtils.substring("abc", 4, 6) = "" StringUtils.substring("abc", 2, 2) = "" StringUtils.substring("abc", -2, -1) = "b" StringUtils.substring("abc", -4, 2) = "ab"
str
- the String to get the substring from, may be nullstart
- the position to start from, negative means count back from the end of the String by this many
charactersend
- the position to end at (exclusive), negative means count back from the end of the String by this many
scharactersnull
if null String inputpublic static java.lang.String upperCase(java.lang.String str)
Converts a String to upper case as per String.toUpperCase()
.
A null
input String returns null
.
StringUtils.upperCase(null) = null StringUtils.upperCase("") = "" StringUtils.upperCase("aBc") = "ABC"
This uses "ENGLISH" as the locale.
str
- the String to upper case, may be nullnull
if null String inputpublic static java.lang.String lowerCase(java.lang.String str)
Converts a String to lower case as per String.toLowerCase()
.
A null
input String returns null
.
StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"
This uses "ENGLISH" as the locale.
str
- the String to lower case, may be nullnull
if null String inputpublic static java.lang.String capitalize(java.lang.String str)
Capitalizes a String changing the first character to title case as
per Character.toTitleCase(int)
. No other characters are changed.
StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt" StringUtils.capitalize("'cat'") = "'cat'"
str
- the String to capitalize, may be nullnull
if null String inputuncapitalize(String)
,
Sourcepublic static java.lang.String uncapitalize(java.lang.String str)
Uncapitalizes a String, changing the first character to lower case as
per Character.toLowerCase(int)
. No other characters are changed.
StringUtils.uncapitalize(null) = null StringUtils.uncapitalize("") = "" StringUtils.uncapitalize("cat") = "cat" StringUtils.uncapitalize("Cat") = "cat" StringUtils.uncapitalize("CAT") = "cAT"
str
- the String to uncapitalize, may be nullnull
if null String inputcapitalize(String)
,
Sourcepublic static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String prefix)
str
- the string to be testedprefix
- the prefixpublic static java.lang.String repeat(java.lang.String str, int repeat)
Repeat a String repeat
times to form a
new String.
StringUtils.repeat(null, 2) = null StringUtils.repeat("", 0) = "" StringUtils.repeat("", 2) = "" StringUtils.repeat("a", 3) = "aaa" StringUtils.repeat("ab", 2) = "abab" StringUtils.repeat("a", -2) = ""
str
- the String to repeat, may be nullrepeat
- number of times to repeat str, negative treated as zeronull
if null String inputpublic static java.lang.String repeat(char ch, int repeat)
Returns padding using the specified delimiter repeated to a given length.
StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = ""
Note: this method does not support padding with
Unicode Supplementary Characters
as they require a pair of char
s to be represented.
If you are needing to support full I18N of your applications
consider using repeat(String, int)
instead.
ch
- character to repeatrepeat
- number of times to repeat char, negative treated as zerorepeat(String, int)
,
Sourcepublic static java.lang.String rightPad(java.lang.String str, int size)
Right pad a String with spaces (' ').
The String is padded to the size of size
.
StringUtils.rightPad(null, *) = null StringUtils.rightPad("", 3) = " " StringUtils.rightPad("bat", 3) = "bat" StringUtils.rightPad("bat", 5) = "bat " StringUtils.rightPad("bat", 1) = "bat" StringUtils.rightPad("bat", -1) = "bat"
str
- the String to pad out, may be nullsize
- the size to pad tonull
if null String inputpublic static java.lang.String rightPad(java.lang.String str, int size, char padChar)
Right pad a String with a specified character.
The String is padded to the size of size
.
StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, 'z') = "zzz" StringUtils.rightPad("bat", 3, 'z') = "bat" StringUtils.rightPad("bat", 5, 'z') = "batzz" StringUtils.rightPad("bat", 1, 'z') = "bat" StringUtils.rightPad("bat", -1, 'z') = "bat"
str
- the String to pad out, may be nullsize
- the size to pad topadChar
- the character to pad withnull
if null String inputpublic static java.lang.String rightPad(java.lang.String str, int size, java.lang.String padStr)
Right pad a String with a specified String.
The String is padded to the size of size
.
StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, "z") = "zzz" StringUtils.rightPad("bat", 3, "yz") = "bat" StringUtils.rightPad("bat", 5, "yz") = "batyz" StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" StringUtils.rightPad("bat", 1, "yz") = "bat" StringUtils.rightPad("bat", -1, "yz") = "bat" StringUtils.rightPad("bat", 5, null) = "bat " StringUtils.rightPad("bat", 5, "") = "bat "
str
- the String to pad out, may be nullsize
- the size to pad topadStr
- the String to pad with, null or empty treated as single spacenull
if null String inputpublic static java.lang.String leftPad(java.lang.String str, int size)
Left pad a String with spaces (' ').
The String is padded to the size of size
.
StringUtils.leftPad(null, *) = null StringUtils.leftPad("", 3) = " " StringUtils.leftPad("bat", 3) = "bat" StringUtils.leftPad("bat", 5) = " bat" StringUtils.leftPad("bat", 1) = "bat" StringUtils.leftPad("bat", -1) = "bat"
str
- the String to pad out, may be nullsize
- the size to pad tonull
if null String inputpublic static java.lang.String leftPad(java.lang.String str, int size, char padChar)
Left pad a String with a specified character.
Pad to a size of size
.
StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, 'z') = "zzz" StringUtils.leftPad("bat", 3, 'z') = "bat" StringUtils.leftPad("bat", 5, 'z') = "zzbat" StringUtils.leftPad("bat", 1, 'z') = "bat" StringUtils.leftPad("bat", -1, 'z') = "bat"
str
- the String to pad out, may be nullsize
- the size to pad topadChar
- the character to pad withnull
if null String inputpublic static java.lang.String leftPad(java.lang.String str, int size, java.lang.String padStr)
Left pad a String with a specified String.
Pad to a size of size
.
StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, "z") = "zzz" StringUtils.leftPad("bat", 3, "yz") = "bat" StringUtils.leftPad("bat", 5, "yz") = "yzbat" StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" StringUtils.leftPad("bat", 1, "yz") = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null) = " bat" StringUtils.leftPad("bat", 5, "") = " bat"
str
- the String to pad out, may be nullsize
- the size to pad topadStr
- the String to pad with, null or empty treated as single spacenull
if null String inputpublic static java.lang.String strip(java.lang.String str, java.lang.String stripChars)
Strips any of a set of characters from the start and end of a String.
This is similar to String.trim()
but allows the characters
to be stripped to be controlled.
A null
input String returns null
.
An empty string ("") input returns the empty string.
If the stripChars String is null
, whitespace is
stripped as defined by Character.isWhitespace(char)
.
StringUtils.strip(null, *) = null StringUtils.strip("", *) = "" StringUtils.strip("abc", null) = "abc" StringUtils.strip(" abc", null) = "abc" StringUtils.strip("abc ", null) = "abc" StringUtils.strip(" abc ", null) = "abc" StringUtils.strip(" abcyx", "xyz") = " abc"
str
- the String to remove characters from, may be nullstripChars
- the characters to remove, null treated as whitespacenull
if null String inputpublic static java.lang.String stripEnd(java.lang.String str, java.lang.String stripChars)
Strips any of a set of characters from the end of a String.
A null
input String returns null
.
An empty string ("") input returns the empty string.
If the stripChars String is null
, whitespace is
stripped as defined by Character.isWhitespace(char)
.
StringUtils.stripEnd(null, *) = null StringUtils.stripEnd("", *) = "" StringUtils.stripEnd("abc", "") = "abc" StringUtils.stripEnd("abc", null) = "abc" StringUtils.stripEnd(" abc", null) = " abc" StringUtils.stripEnd("abc ", null) = "abc" StringUtils.stripEnd(" abc ", null) = " abc" StringUtils.stripEnd(" abcyx", "xyz") = " abc" StringUtils.stripEnd("120.00", ".0") = "12"
str
- the String to remove characters from, may be nullstripChars
- the set of characters to remove, null treated as whitespacenull
if null String inputpublic static java.lang.String stripStart(java.lang.String str, java.lang.String stripChars)
Strips any of a set of characters from the start of a String.
A null
input String returns null
.
An empty string ("") input returns the empty string.
If the stripChars String is null
, whitespace is
stripped as defined by Character.isWhitespace(char)
.
StringUtils.stripStart(null, *) = null StringUtils.stripStart("", *) = "" StringUtils.stripStart("abc", "") = "abc" StringUtils.stripStart("abc", null) = "abc" StringUtils.stripStart(" abc", null) = "abc" StringUtils.stripStart("abc ", null) = "abc " StringUtils.stripStart(" abc ", null) = "abc " StringUtils.stripStart("yxabc ", "xyz") = "abc "
str
- the String to remove characters from, may be nullstripChars
- the characters to remove, null treated as whitespacenull
if null String inputpublic static java.lang.String stripToEmpty(java.lang.String str)
Strips whitespace from the start and end of a String returning
an empty String if null
input.
This is similar to trimToEmpty(String)
but removes whitespace.
Whitespace is defined by Character.isWhitespace(char)
.
StringUtils.stripToEmpty(null) = "" StringUtils.stripToEmpty("") = "" StringUtils.stripToEmpty(" ") = "" StringUtils.stripToEmpty("abc") = "abc" StringUtils.stripToEmpty(" abc") = "abc" StringUtils.stripToEmpty("abc ") = "abc" StringUtils.stripToEmpty(" abc ") = "abc" StringUtils.stripToEmpty(" ab c ") = "ab c"
str
- the String to be stripped, may be nullnull
inputpublic static java.lang.String wrap(java.lang.String str, int wrapLength)
Wraps a single line of text, identifying words by ' '
.
New lines will be separated by the system property line separator. Very long words, such as URLs will not be wrapped.
Leading spaces on a new line are stripped. Trailing spaces are not stripped.
input | wrapLength | result |
---|---|---|
null | * | null |
"" | * | "" |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | "Here is one line of\ntext that is going\nto be wrapped after\n20 columns." |
"Click here to jump to the commons website - http://commons.apache.org" | 20 | "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org" |
"Click here, http://commons.apache.org, to jump to the commons website" | 20 | "Click here,\nhttp://commons.apache.org,\nto jump to the\ncommons website" |
str
- the String to be word wrapped, may be nullwrapLength
- the column to wrap the words at, less than 1 is treated as 1null
if null inputpublic static java.lang.String wrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords)
Wraps a single line of text, identifying words by ' '
.
Leading spaces on a new line are stripped. Trailing spaces are not stripped.
input | wrapLength | newLineString | wrapLongWords | result |
---|---|---|---|---|
null | * | * | true/false | null |
"" | * | * | true/false | "" |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | "\n" | true/false | "Here is one line of\ntext that is going\nto be wrapped after\n20 columns." |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | "<br />" | true/false | "Here is one line of<br />text that is going< br />to be wrapped after<br />20 columns." |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | null | true/false | "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns." |
"Click here to jump to the commons website - http://commons.apache.org" | 20 | "\n" | false | "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org" |
"Click here to jump to the commons website - http://commons.apache.org" | 20 | "\n" | true | "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apach\ne.org" |
str
- the String to be word wrapped, may be nullwrapLength
- the column to wrap the words at, less than 1 is treated as 1newLineStr
- the string to insert for a new line,
null
uses the system property line separatorwrapLongWords
- true if long words (such as URLs) should be wrappednull
if null inputpublic static java.lang.String wrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords, java.lang.String wrapOn)
Wraps a single line of text, identifying words by wrapOn
.
Leading spaces on a new line are stripped. Trailing spaces are not stripped.
input | wrapLength | newLineString | wrapLongWords | wrapOn | result |
---|---|---|---|---|---|
null | * | * | true/false | * | null |
"" | * | * | true/false | * | "" |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | "\n" | true/false | " " | "Here is one line of\ntext that is going\nto be wrapped after\n20 columns." |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | "<br />" | true/false | " " | "Here is one line of<br />text that is going<br /> to be wrapped after<br />20 columns." |
"Here is one line of text that is going to be wrapped after 20 columns." | 20 | null | true/false | " " | "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns." |
"Click here to jump to the commons website - http://commons.apache.org" | 20 | "\n" | false | " " | "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org" |
"Click here to jump to the commons website - http://commons.apache.org" | 20 | "\n" | true | " " | "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apach\ne.org" |
"flammable/inflammable" | 20 | "\n" | true | "/" | "flammable\ninflammable" |
str
- the String to be word wrapped, may be nullwrapLength
- the column to wrap the words at, less than 1 is treated as 1newLineStr
- the string to insert for a new line,
null
uses the system property line separatorwrapLongWords
- true if long words (such as URLs) should be wrappedwrapOn
- regex expression to be used as a breakable characters,
if blank string is provided a space character will be usednull
if null inputpublic static java.lang.String escapeJavaString(java.lang.Object object, java.lang.String indent)
public static int levenshteinDistance(java.lang.CharSequence left, java.lang.CharSequence right, int threshold)
This code is a copy of the limitedCompare
method from
Apache commons-text LevenshteinDistance.java.
This implementation follows from Algorithms on Strings, Trees and Sequences by Dan Gusfield and Chas Emerick's implementation of the Levenshtein distance algorithm from http://www.merriampark.com/ld.htm
limitedCompare(null, *, *) = IllegalArgumentException limitedCompare(*, null, *) = IllegalArgumentException limitedCompare(*, *, -1) = IllegalArgumentException limitedCompare("","", 0) = 0 limitedCompare("aaapppp", "", 8) = 7 limitedCompare("aaapppp", "", 7) = 7 limitedCompare("aaapppp", "", 6)) = -1 limitedCompare("elephant", "hippo", 7) = 7 limitedCompare("elephant", "hippo", 6) = -1 limitedCompare("hippo", "elephant", 7) = 7 limitedCompare("hippo", "elephant", 6) = -1
left
- the first CharSequence, must not be nullright
- the second CharSequence, must not be nullthreshold
- the target threshold, must not be negative