public static String deflate(String previous,String current){
  if (previous == null)   return current;
  StringBuilder buf=new StringBuilder();
  int start1=0;
  int start2=0;
  while (start1 < previous.length() && start2 < current.length()) {
    int end1=start1;
    int end2=start2;
    while (end1 <= previous.length() && end2 <= current.length()) {
      int c1=(end1 < previous.length() ? previous.charAt(end1) : '\t');
      int c2=(end2 < current.length() ? current.charAt(end2) : '\t');
      if (c1 == c2) {
        if (c1 == '\t') {
          buf.append("&");
          break;
        }
 else {
          end1++;
          end2++;
        }
      }
 else {
        while (end1 < previous.length() && previous.charAt(end1) != '\t') {
          end1++;
        }
        while (end2 < current.length() && current.charAt(end2) != '\t') {
          end2++;
        }
        for (int i=start2; i < end2; i++)         buf.append(current.charAt(i));
        break;
      }
    }
    start1=end1 + 1;
    start2=end2 + 1;
    if (start2 < current.length())     buf.append("\t");
  }
  return buf.toString();
}

public static String deflate ( String previous , String current ) { if ( previous == null ) return current ; StringBuilder buf = new StringBuilder ( ) ; int start1 = 0 ; int start2 = 0 ; while ( start1 < previous . length ( ) && start2 < current . length ( ) ) { int end1 = start1 ; int end2 = start2 ; while ( end1 <= previous . length ( ) && end2 <= current . length ( ) ) { int c1 = ( end1 < previous . length ( ) ? previous . charAt ( end1 ) : '\t' ) ; int c2 = ( end2 < current . length ( ) ? current . charAt ( end2 ) : '\t' ) ; if ( c1 == c2 ) { if ( c1 == '\t' ) { buf . append ( "&" ) ; break ; } else { end1 ++ ; end2 ++ ; } } else { while ( end1 < previous . length ( ) && previous . charAt ( end1 ) != '\t' ) { end1 ++ ; } while ( end2 < current . length ( ) && current . charAt ( end2 ) != '\t' ) { end2 ++ ; } for ( int i = start2 ; i < end2 ; i ++ ) buf . append ( current . charAt ( i ) ) ; break ; } } start1 = end1 + 1 ; start2 = end2 + 1 ; if ( start2 < current . length ( ) ) buf . append ( "\t" ) ; } return buf . toString ( ) ; }
deflate current sam line by replacing all fields that equalovershorterofboth previous line by an ampersand
