public static List < int [ ] > hunks ( String s0 , String s1 ) { List < int [ ] > lcs = longestCommonSubsequence ( s0 , s1 ) ; List < int [ ] > hunks = new ArrayList < int [ ] > ( ) ; int inf0 = - 1 ; int inf1 = - 1 ; int last0 = - 1 ; int last1 = - 1 ; for ( int i = 0 ; i < lcs . size ( ) ; i ++ ) { int [ ] match = lcs . get ( i ) ; if ( inf0 == - 1 || inf1 == - 1 ) { inf0 = match [ 0 ] ; inf1 = match [ 1 ] ; } else if ( last0 + 1 != match [ 0 ] || last1 + 1 != match [ 1 ] ) { hunks . add ( new int [ ] { inf0 , last0 + 1 , inf1 , last1 + 1 } ) ; inf0 = match [ 0 ] ; inf1 = match [ 1 ] ; } else if ( i == lcs . size ( ) - 1 ) { hunks . add ( new int [ ] { inf0 , match [ 0 ] + 1 , inf1 , match [ 1 ] + 1 } ) ; break ; } last0 = match [ 0 ] ; last1 = match [ 1 ] ; } return hunks ; }
Returns the hunks of the longest common subsequence between s1 and s2 .