LineOnOtherInfo lineOnOther(DisplaySide mySide,int line){
  List<LineGap> lineGaps=gapList(mySide);
  int ret=Collections.binarySearch(lineGaps,new LineGap(line));
  if (ret == -1) {
    return new LineOnOtherInfo(line,true);
  }
  LineGap lookup=lineGaps.get(0 <= ret ? ret : -ret - 2);
  int start=lookup.start;
  int end=lookup.end;
  int delta=lookup.delta;
  if (start <= line && line <= end && end != -1) {
    return new LineOnOtherInfo(end + delta,false);
  }
  return new LineOnOtherInfo(line + delta,true);
}

LineOnOtherInfo lineOnOther ( DisplaySide mySide , int line ) { List < LineGap > lineGaps = gapList ( mySide ) ; int ret = Collections . binarySearch ( lineGaps , new LineGap ( line ) ) ; if ( ret == - 1 ) { return new LineOnOtherInfo ( line , true ) ; } LineGap lookup = lineGaps . get ( 0 <= ret ? ret : - ret - 2 ) ; int start = lookup . start ; int end = lookup . end ; int delta = lookup . delta ; if ( start <= line && line <= end && end != - 1 ) { return new LineOnOtherInfo ( end + delta , false ) ; } return new LineOnOtherInfo ( line + delta , true ) ; }
helper method to retrieve the line number on the other side . given a line number on one side , performs a binary search in the linemap to find the corresponding linegap record . a linegap records gap information from the start of an actual gap up to the start of the next gap . in the following example , linemapatob will have linegap : { start : 1 , end : - 1 , delta : 3 } ( end set to - 1 to represent a dummy gap of length zero . the binary search only looks at start so setting it to - 1 has no effect here . ) linemapbtoa will have linegap : { start : 1 , end : 3 , delta : - 3 } these linegaps control lines between 1 and 5 . the " delta " is computed as the number to add on our side to get the line number on the other side given a line after the actual gap , so the result will be ( line + delta ) . all lines within the actual gap ( 1 to 3 ) are considered corresponding to the last line above the region on the other side , which is 0 in this case . for these lines , we do ( end + delta ) . for example , to get the line number on the left corresponding to 1 on the right ( lineonother ( revision , 1 ) ) , the method looks up in linemapbtoa , finds the " delta " to be - 3 , and returns 3 + ( - 3 ) = 0 since 1 falls in the actual gap . on the other hand , the line corresponding to 5 on the right will be 5 + ( - 3 ) = 2 , since 5 is in the region after the gap ( but still controlled by the current linegap ) . parent revision 0 | 0 - | 1 \ \ - | 2 | actual insertion gap | - | 3 / | region controlled by one linegap 1 | 4 < - delta = 4 - 1 = 3 | 2 | 5 / - | 6 . . .
