int displayToPhysical(int displayIndex) {
    final XmlAttributeDelegate.VolatileState state = getFreshState();
    if (state == null) return -1;
    final String displayValue = state.myDisplayText;
    if (displayIndex < 0 || displayIndex > displayValue.length()) return -1;

    final int[] gapDisplayStarts = state.myGapDisplayStarts;
    if (gapDisplayStarts.length == 0) return displayIndex;

    final int bsResult = Arrays.binarySearch(gapDisplayStarts, displayIndex);
    final int gapIndex;

    if (bsResult > 0) {
      gapIndex = bsResult - 1;
    }
    else if (bsResult < -1) {
      gapIndex = -bsResult - 2;
    }
    else {
      gapIndex = -1;
    }

    if (gapIndex < 0) return displayIndex;
    final int shift = state.myGapPhysicalStarts[gapIndex] - gapDisplayStarts[gapIndex];
    return displayIndex + shift;
  }
int displayToPhysical(int displayIndex)