Top Description Fields Constructors Methods
org.glassfish.jaxb.core.v2.util

public Class EditDistance

extends Object
Class Inheritance
Imports
java.util.AbstractMap, .Arrays, .Collection, .WeakHashMap

Computes the string edit distance.

Refer to a computer science text book for the definition of the "string edit distance".

Author
Kohsuke Kawaguchi ([email protected])

Field Summary

Modifier and TypeField and Description
private final String
a

Two strings to be compared.

private final String
b

Two strings to be compared.

private int[]
back

back buffer.

private static final WeakHashMap<AbstractMap.SimpleEntry<String, String>, Integer>
CACHE

Weak results cache to avoid additional computations.

private int[]
cost

cost vector.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private int
calc()

public static int
editDistance(String a, String b)

Computes the edit distance between two strings.

public static String

Returns:

null if group.length==0.
findNearest
(String key, String[] group)

Finds the string in the group closest to key and returns it.

public static String

Returns:

null if group.length==0.
findNearest
(String key, Collection<String> group)

Finds the string in the group closest to key and returns it.

private void
flip()

Swaps two buffers.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final String a

Two strings to be compared.

bback to summary
private final String b

Two strings to be compared.

backback to summary
private int[] back

back buffer.

CACHEback to summary
private static final WeakHashMap<AbstractMap.SimpleEntry<String, String>, Integer> CACHE

Weak results cache to avoid additional computations. Because of high complexity caching is required.

costback to summary
private int[] cost

cost vector.

Constructor Detail

EditDistanceback to summary
private EditDistance(String a, String b)

Method Detail

calcback to summary
private int calc()
editDistanceback to summary
public static int editDistance(String a, String b)

Computes the edit distance between two strings.

The complexity is O(nm) where n=a.length() and m=b.length().

findNearestback to summary
public static String findNearest(String key, String[] group)

Finds the string in the group closest to key and returns it.

Returns:String

null if group.length==0.

findNearestback to summary
public static String findNearest(String key, Collection<String> group)

Finds the string in the group closest to key and returns it.

Returns:String

null if group.length==0.

flipback to summary
private void flip()

Swaps two buffers.

minback to summary
private int min(int a, int b, int c)