Class StringUtils

java.lang.Object
software.amazon.smithy.utils.StringUtils

public final class StringUtils extends Object

Operations on String that are null safe.

  • IsEmpty/IsBlank - checks if a String contains text
  • Trim - removes leading and trailing whitespace
  • Equals/Compare - compares two strings null-safe
  • Substring - null-safe substring extraction
  • UpperCase/LowerCase/Capitalize/Uncapitalize - changes the case of a String

The StringUtils class defines certain words related to String handling.

  • null - null
  • empty - a zero-length string ("")
  • space - the space character (' ', char 32)
  • whitespace - the characters defined by Character.isWhitespace(char)
  • trim - the characters <= 32 as in 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#

See Also:
  • Method Details

    • isEmpty

      public static boolean isEmpty(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().

      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is empty or null
      Since:
      3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
      See Also:
    • isBlank

      public static boolean isBlank(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
       
      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is null, empty or whitespace only
      Since:
      2.0, 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
      See Also:
    • isNotBlank

      public static boolean isNotBlank(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
       
      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is not empty and not null and not whitespace only
      Since:
      2.0, 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence)
      See Also:
    • trim

      public static String trim(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"
       
      Parameters:
      str - the String to be trimmed, may be null
      Returns:
      the trimmed string, null if null String input
      See Also:
    • trimToNull

      public static String trimToNull(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"
       
      Parameters:
      str - the String to be trimmed, may be null
      Returns:
      the trimmed String, null if only chars <= 32, empty or null String input
      Since:
      2.0
      See Also:
    • trimToEmpty

      public static String trimToEmpty(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"
       
      Parameters:
      str - the String to be trimmed, may be null
      Returns:
      the trimmed String, or an empty String if null input
      Since:
      2.0
      See Also:
    • equals

      public static boolean equals(String cs1, String cs2)

      Compares two Strings, returning true if they represent equal sequences of characters.

      nulls 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
       
      Parameters:
      cs1 - the first String, may be null
      cs2 - the second String, may be null
      Returns:
      true if the Strings are equal (case-sensitive), or both null
      See Also:
    • substring

      public static String substring(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"
       
      Parameters:
      str - the String to get the substring from, may be null
      start - the position to start from, negative means count back from the end of the String by this many characters
      Returns:
      substring from start position, null if null String input
      See Also:
    • substring

      public static String substring(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"
       
      Parameters:
      str - the String to get the substring from, may be null
      start - the position to start from, negative means count back from the end of the String by this many characters
      end - the position to end at (exclusive), negative means count back from the end of the String by this many scharacters
      Returns:
      substring from start position to end position, null if null String input
      See Also:
    • upperCase

      public static String upperCase(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.

      Parameters:
      str - the String to upper case, may be null
      Returns:
      the upper cased String, null if null String input
      See Also:
    • lowerCase

      public static String lowerCase(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.

      Parameters:
      str - the String to lower case, may be null
      Returns:
      the lower cased String, null if null String input
      See Also:
    • capitalize

      public static String capitalize(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'"
       
      Parameters:
      str - the String to capitalize, may be null
      Returns:
      the capitalized String, null if null String input
      Since:
      2.0
      See Also:
    • uncapitalize

      public static String uncapitalize(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"
       
      Parameters:
      str - the String to uncapitalize, may be null
      Returns:
      the uncapitalized String, null if null String input
      Since:
      2.0
      See Also:
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(String str, String prefix)
      Tests if this string starts with the specified prefix ignoring case considerations.
      Parameters:
      str - the string to be tested
      prefix - the prefix
      Returns:
      true if the string starts with the prefix ignoring case
    • repeat

      public static String repeat(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) = ""
       
      Parameters:
      str - the String to repeat, may be null
      repeat - number of times to repeat str, negative treated as zero
      Returns:
      a new String consisting of the original String repeated, null if null String input
      See Also:
    • repeat

      public static 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 chars to be represented. If you are needing to support full I18N of your applications consider using repeat(String, int) instead.

      Parameters:
      ch - character to repeat
      repeat - number of times to repeat char, negative treated as zero
      Returns:
      String with repeated character
      See Also:
    • rightPad

      public static String rightPad(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"
       
      Parameters:
      str - the String to pad out, may be null
      size - the size to pad to
      Returns:
      right padded String or original String if no padding is necessary, null if null String input
      See Also:
    • rightPad

      public static String rightPad(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"
       
      Parameters:
      str - the String to pad out, may be null
      size - the size to pad to
      padChar - the character to pad with
      Returns:
      right padded String or original String if no padding is necessary, null if null String input
      Since:
      2.0
      See Also:
    • rightPad

      public static String rightPad(String str, int size, 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  "
       
      Parameters:
      str - the String to pad out, may be null
      size - the size to pad to
      padStr - the String to pad with, null or empty treated as single space
      Returns:
      right padded String or original String if no padding is necessary, null if null String input
      See Also:
    • leftPad

      public static String leftPad(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"
       
      Parameters:
      str - the String to pad out, may be null
      size - the size to pad to
      Returns:
      left padded String or original String if no padding is necessary, null if null String input
      See Also:
    • leftPad

      public static String leftPad(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"
       
      Parameters:
      str - the String to pad out, may be null
      size - the size to pad to
      padChar - the character to pad with
      Returns:
      left padded String or original String if no padding is necessary, null if null String input
      Since:
      2.0
      See Also:
    • leftPad

      public static String leftPad(String str, int size, 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"
       
      Parameters:
      str - the String to pad out, may be null
      size - the size to pad to
      padStr - the String to pad with, null or empty treated as single space
      Returns:
      left padded String or original String if no padding is necessary, null if null String input
      See Also:
    • strip

      public static String strip(String str, 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"
       
      Parameters:
      str - the String to remove characters from, may be null
      stripChars - the characters to remove, null treated as whitespace
      Returns:
      the stripped String, null if null String input
      See Also:
    • stripEnd

      public static String stripEnd(String str, 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"
       
      Parameters:
      str - the String to remove characters from, may be null
      stripChars - the set of characters to remove, null treated as whitespace
      Returns:
      the stripped String, null if null String input
      See Also:
    • stripStart

      public static String stripStart(String str, 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  "
       
      Parameters:
      str - the String to remove characters from, may be null
      stripChars - the characters to remove, null treated as whitespace
      Returns:
      the stripped String, null if null String input
      See Also:
    • stripToEmpty

      public static String stripToEmpty(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"
       
      Parameters:
      str - the String to be stripped, may be null
      Returns:
      the trimmed String, or an empty String if null input
      Since:
      2.0
      See Also:
    • wrap

      public static String wrap(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.

      Examples
      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"
      (assuming that '\n' is the systems line separator)
      Parameters:
      str - the String to be word wrapped, may be null
      wrapLength - the column to wrap the words at, less than 1 is treated as 1
      Returns:
      a line with newlines inserted, null if null input
      See Also:
    • wrap

      public static String wrap(String str, int wrapLength, 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.

      Examples
      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"
      Parameters:
      str - the String to be word wrapped, may be null
      wrapLength - the column to wrap the words at, less than 1 is treated as 1
      newLineStr - the string to insert for a new line, null uses the system property line separator
      wrapLongWords - true if long words (such as URLs) should be wrapped
      Returns:
      a line with newlines inserted, null if null input
      See Also:
    • wrap

      public static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords, 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.

      Examples
      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"
      Parameters:
      str - the String to be word wrapped, may be null
      wrapLength - the column to wrap the words at, less than 1 is treated as 1
      newLineStr - the string to insert for a new line, null uses the system property line separator
      wrapLongWords - true if long words (such as URLs) should be wrapped
      wrapOn - regex expression to be used as a breakable characters, if blank string is provided a space character will be used
      Returns:
      a line with newlines inserted, null if null input
      See Also:
    • escapeJavaString

      public static String escapeJavaString(Object object, String indent)
    • levenshteinDistance

      public static int levenshteinDistance(CharSequence left, CharSequence right, int threshold)
      Find the Levenshtein distance between two CharSequences if it's less than or equal to a given 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
       
      Parameters:
      left - the first CharSequence, must not be null
      right - the second CharSequence, must not be null
      threshold - the target threshold, must not be negative
      Returns:
      result distance, or -1
      See Also: