public static double quickRatio ( final String paramFirst , final String paramSecond ) { if ( paramFirst == null || paramSecond == null ) { return 1 ; } double matches = 0 ; // Use a sparse array to reduce the memory usage // for unicode characters. final int x [ ] [ ] = new int [ 256 ] [ ] ; for ( char c : paramSecond . toCharArray ( ) ) { if ( x [ c >> 8 ] == null ) { x [ c >> 8 ] = new int [ 256 ] ; } x [ c >> 8 ] [ c & 0xFF ] ++ ; } for ( char c : paramFirst . toCharArray ( ) ) { final int n = ( x [ c >> 8 ] == null ) ? 0 : x [ c >> 8 ] [ c & 0xFF ] -- ; if ( n > 0 ) { matches ++ ; } } return 2.0 * matches / ( paramFirst . length ( ) + paramSecond . length ( ) ) ; }
Calculates the similarity of two strings . This is done by comparing the frequency each character occures in both strings .