public class Strings extends Object
| Constructor and Description |
|---|
Strings() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areEqual(String left,
String right) |
static boolean |
areEqualTrimmed(String left,
String right) |
static String |
capitalize(String input)
Capitalize the given String: "input" -> "Input"
|
static String |
enquote(String value) |
static int |
getLevenshteinDistance(CharSequence s,
CharSequence t)
Find the Levenshtein distance between two Strings.
|
static int |
getLevenshteinDistance(CharSequence s,
CharSequence t,
int threshold)
Find the Levenshtein distance between two Strings if it's less than or equal to a given threshold.
|
static boolean |
isNullOrEmpty(String string) |
static boolean |
isTrue(String value) |
static String |
join(Collection<?> collection,
String delimiter) |
static String |
stripQuotes(String value) |
static String |
uncapitalize(String input) |
static String |
unquote(String value) |
public static String capitalize(String input)
public static String join(Collection<?> collection, String delimiter)
public static boolean isNullOrEmpty(String string)
public static boolean isTrue(String value)
public static int getLevenshteinDistance(CharSequence s, CharSequence t)
Find the Levenshtein distance between two Strings.
This is the number of changes needed to change one String into another, where each change is a single character modification (deletion, insertion or substitution).
The previous implementation of the Levenshtein distance algorithm was from http://www.merriampark.com/ld.htm
Chas Emerick has written an implementation in Java, which avoids an OutOfMemoryError which can occur when my Java
implementation is used with very large strings.
This implementation of the Levenshtein distance algorithm is from http://www.merriampark.com/ldjava.htm
StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException
StringUtils.getLevenshteinDistance(*, null) = IllegalArgumentException
StringUtils.getLevenshteinDistance("","") = 0
StringUtils.getLevenshteinDistance("","a") = 1
StringUtils.getLevenshteinDistance("aaapppp", "") = 7
StringUtils.getLevenshteinDistance("frog", "fog") = 1
StringUtils.getLevenshteinDistance("fly", "ant") = 3
StringUtils.getLevenshteinDistance("elephant", "hippo") = 7
StringUtils.getLevenshteinDistance("hippo", "elephant") = 7
StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz") = 8
StringUtils.getLevenshteinDistance("hello", "hallo") = 1
s - the first String, must not be nullt - the second String, must not be nullIllegalArgumentException - if either String input nullpublic static int getLevenshteinDistance(CharSequence s, CharSequence t, int threshold)
Find the Levenshtein distance between two Strings if it's less than or equal to a given threshold.
This is the number of changes needed to change one String into another, where each change is a single character modification (deletion, insertion or substitution).
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
StringUtils.getLevenshteinDistance(null, *, *) = IllegalArgumentException
StringUtils.getLevenshteinDistance(*, null, *) = IllegalArgumentException
StringUtils.getLevenshteinDistance(*, *, -1) = IllegalArgumentException
StringUtils.getLevenshteinDistance("","", 0) = 0
StringUtils.getLevenshteinDistance("aaapppp", "", 8) = 7
StringUtils.getLevenshteinDistance("aaapppp", "", 7) = 7
StringUtils.getLevenshteinDistance("aaapppp", "", 6)) = -1
StringUtils.getLevenshteinDistance("elephant", "hippo", 7) = 7
StringUtils.getLevenshteinDistance("elephant", "hippo", 6) = -1
StringUtils.getLevenshteinDistance("hippo", "elephant", 7) = 7
StringUtils.getLevenshteinDistance("hippo", "elephant", 6) = -1
s - the first String, must not be nullt - the second String, must not be nullthreshold - the target threshold, must not be negative-1 if the distance would be greater than the thresholdIllegalArgumentException - if either String input null or negative thresholdCopyright © 2013 JBoss by Red Hat. All Rights Reserved.