public static int levenshteinDistance(String o1,String o2,int prefix,int postfix){
  final int l1=o1.length(), l2=o2.length();
  int[] buf=new int[(l2 + 1 - (prefix + postfix)) << 1];
  for (int j=0; j < buf.length; j+=2) {
    buf[j]=j >> 1;
  }
  int inter=1;
  for (int i=prefix, e1=l1 - postfix; i < e1; i++, inter^=1) {
    final char chr=o1.charAt(i);
    buf[inter]=i + 1 - prefix;
    for (int c=2 + inter, p=3 - inter, j=prefix; c < buf.length; c+=2, p+=2) {
      buf[c]=min(buf[p] + 1,buf[c - 2] + 1,buf[p - 2] + ((chr == o2.charAt(j++)) ? 0 : 1));
    }
  }
  return buf[buf.length - 2 + (inter ^ 1)];
}

public static int levenshteinDistance ( String o1 , String o2 , int prefix , int postfix ) { final int l1 = o1 . length ( ) , l2 = o2 . length ( ) ; int [ ] buf = new int [ ( l2 + 1 - ( prefix + postfix ) ) << 1 ] ; for ( int j = 0 ; j < buf . length ; j += 2 ) { buf [ j ] = j > > 1 ; } int inter = 1 ; for ( int i = prefix , e1 = l1 - postfix ; i < e1 ; i ++ , inter ^= 1 ) { final char chr = o1 . charAt ( i ) ; buf [ inter ] = i + 1 - prefix ; for ( int c = 2 + inter , p = 3 - inter , j = prefix ; c < buf . length ; c += 2 , p += 2 ) { buf [ c ] = min ( buf [ p ] + 1 , buf [ c - 2 ] + 1 , buf [ p - 2 ] + ( ( chr == o2 . charAt ( j ++ ) ) ? 0 : 1 ) ) ; } } return buf [ buf . length - 2 + ( inter ^ 1 ) ] ; }
compute the levenshtein distance , except for prefix and postfix .
