APIdia Launch Partner
Top Description Inners Constructors Methods
com.sun.tools.javac.util

public Class StringUtils

extends Object
Class Inheritance
Imports
java.util.HashMap, .Locale, .Map, java.util.regex.Matcher, .Pattern

A collection of utilities for String manipulation.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static int
indexOfIgnoreCase(String text, String str)

Case insensitive version of String#indexOf(java.lang.String).

public static int
indexOfIgnoreCase(String text, String str, int startIndex)

Case insensitive version of String#indexOf(java.lang.String, int).

public static String
toLowerCase(String source)

Converts the given String to lower case using the US Locale.

public static String
toUpperCase(String source)

Converts the given String to upper case using the US Locale.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

StringUtilsback to summary
public StringUtils()

Method Detail

indexOfIgnoreCaseback to summary
public static int indexOfIgnoreCase(String text, String str)

Case insensitive version of String#indexOf(java.lang.String). Equivalent to text.indexOf(str), except the matching is case insensitive.

indexOfIgnoreCaseback to summary
public static int indexOfIgnoreCase(String text, String str, int startIndex)

Case insensitive version of String#indexOf(java.lang.String, int). Equivalent to text.indexOf(str, startIndex), except the matching is case insensitive.

toLowerCaseback to summary
public static String toLowerCase(String source)

Converts the given String to lower case using the US Locale. The result is independent of the default Locale in the current JVM instance.

toUpperCaseback to summary
public static String toUpperCase(String source)

Converts the given String to upper case using the US Locale. The result is independent of the default Locale in the current JVM instance.

com.sun.tools.javac.util back to summary

public final Class StringUtils.DamerauLevenshteinDistance

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.tools.javac.util.StringUtils.DamerauLevenshteinDistance

Call of(String, String) to calculate the distance.

Usage Examples

Pick top three vocabulary words whose normalized distance from the misspelled word is no greater than one-third.
record Pair(String word, int distance) { } var suggestions = vocabulary.stream() .map(v -> new Pair(v, DamerauLevenshteinDistance.of(v, misspelledWord))) .filter(p -> Double.compare(1.0 / 3, ((double) p.distance()) / p.word().length()) >= 0) .sorted(Comparator.comparingDouble(Pair::distance)) .limit(3) .toList();
record Pair(String word, int distance) { }

var suggestions = vocabulary.stream()
        .map(v -> new Pair(v, DamerauLevenshteinDistance.of(v, misspelledWord)))
        .filter(p -> Double.compare(1.0 / 3, ((double) p.distance()) / p.word().length()) >= 0)
        .sorted(Comparator.comparingDouble(Pair::distance))
        .limit(3)
        .toList();

Field Summary

Modifier and TypeField and Description
private final String
a

private final String
b

private Map<Character, Integer>
private final int[][]
h

private final int
private int[]
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private int
private int
characterAt(String s, int i)

private int
da(int i)

private void
da(int i, int value)

private void
h(int i, int j, int value)

private int
h(int i, int j)

private static int
min(int a, int b, int c, int d)

public static int

Returns:

the edit distance between two strings
of
(String a, String b)

Returns the edit distance between two strings.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final String a
bback to summary
private final String b
bigDAback to summary
private Map<Character, Integer> bigDA
hback to summary
private final int[][] h
INFback to summary
private final int INF
smallDAback to summary
private int[] smallDA
Wcback to summary
private static final int Wc
Wdback to summary
private static final int Wd
Wiback to summary
private static final int Wi
Wsback to summary
private static final int Ws

Constructor Detail

DamerauLevenshteinDistanceback to summary
private DamerauLevenshteinDistance(String a, String b)

Method Detail

calculateback to summary
private int calculate()
characterAtback to summary
private int characterAt(String s, int i)
daback to summary
private int da(int i)
daback to summary
private void da(int i, int value)
hback to summary
private void h(int i, int j, int value)
hback to summary
private int h(int i, int j)
minback to summary
private static int min(int a, int b, int c, int d)
ofback to summary
public static int of(String a, String b)

Returns the edit distance between two strings. The distance returned from this method has the following properties:

  1. a.equals(b) && of(a, b) == 0) || (!a.equals(b) && of(a, b) > 0)
  2. of(a, b) == of(b, a)
  3. of(a, b) + of(b, c) >= of(a, c)

Implementation Specification

This method is safe to be called by multiple threads.

Returns:int

the edit distance between two strings

Exceptions
NullPointerException:
if any of the two strings are null
ArithmeticException:
if any step of the calculation overflows an int