@@ -0,0 +1,1820 @@
+/*%0A * FindBugs - Find Bugs in Java programs%0A * Copyright (C) 2003-2008 University of Maryland%0A * %0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Lesser General Public%0A * License as published by the Free Software Foundation; either%0A * version 2.1 of the License, or (at your option) any later version.%0A * %0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A * %0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this library; if not, write to the Free Software%0A * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0A%0Apackage edu.umd.cs.findbugs.util;%0A%0A/**%0A * @author pwilliam%0A */%0Apublic class EditDistance %7B%0A%09private static int minimum(int a, int b, int c)%7B%0A%09%09if (a %3E b) return Math.min(b, c);%0A%09%09return Math.min(a, c);%0A%09%7D%0A%0A%09private static int distance(char a, char b) %7B%0A%09%09if (a == b) return 0;%0A%09%09if (Character.toLowerCase(a) == Character.toLowerCase(b))%0A%09%09%09return 1;%0A%09%09return 2;%0A%09%7D%0A%09public static int editDistance(String str1, String%0A%09%09%09%09%09%09%09%09%09%09%09%09 str2) %7B%0A%09%09int n1 = str1.length();%0A%09%09int n2 = str2.length();%0A%09%09int diff = Math.abs(n1-n2);%0A%09%09if (diff %3E 3)%0A%09%09%09return 2*diff;%0A%09%09int%5B%5D%5B%5D distance = new int%5Bn1+1%5D%5B%5D;%0A%0A%09%09for(int i=0; i%3C=n1; i++)%7B%0A%09%09%09distance%5Bi%5D = new int%5Bn2+1%5D;%0A%09%09%09distance%5Bi%5D%5B0%5D = 2*i;%0A%09%09%7D%0A%09%09for(int j=1; j%3C= n2; j++)%0A%09%09%09distance%5B0%5D%5Bj%5D=2*j;%0A%0A%09%09for(int i=1; i%3C=n1; i++)%0A%09%09%09for(int j=1;j%3C=n2; j++)%0A%09%09%09%09distance%5Bi%5D%5Bj%5D= minimum(distance%5Bi-1%5D%5Bj%5D+2,%0A%09%09%09%09%09%09%09%09%09%09distance%5Bi%5D%5Bj-1%5D+2,%0A%09%09%09%09%09%09%09%09%09%09distance%5Bi-1%5D%5Bj-1%5D+distance(str1.charAt(i-1), str2.charAt(j-1)));%0A%09%09%09%09%0A%0A%09%09return distance%5Bn1%5D%5Bn2%5D;%0A%09%7D%0A%7D

use string edit distance in identifying mistargeted field/variable references