/** * Moves the gap to <code>offset + add</code>, moving any content after * <code>offset + remove</code> behind the gap. The gap size is kept between 0 and * {@link #fThreshold}, leading to re-allocation if needed. The content between * <code>offset</code> and <code>offset + add</code> is undefined after this operation. * * @param offset the offset at which a change happens * @param remove the number of character which are removed or overwritten at <code>offset</code> * @param add the number of character which are inserted or overwriting at <code>offset</code> */ private void adjustGap(int offset, int remove, int add) { final int oldGapSize= gapSize(); final int newGapSize= oldGapSize - add + remove; final boolean reuseArray= 0 <= newGapSize && newGapSize <= fThreshold; final int newGapStart= offset + add; final int newGapEnd; if (reuseArray) newGapEnd= moveGap(offset, remove, oldGapSize, newGapSize, newGapStart); else newGapEnd= reallocate(offset, remove, oldGapSize, newGapSize, newGapStart); fGapStart= newGapStart; fGapEnd= newGapEnd; }
/** * Moves the gap to <code>offset + add</code>, moving any content after * <code>offset + remove</code> behind the gap. The gap size is kept between 0 and * {@link #fThreshold}, leading to re-allocation if needed. The content between * <code>offset</code> and <code>offset + add</code> is undefined after this operation. * * @param offset the offset at which a change happens * @param remove the number of character which are removed or overwritten at <code>offset</code> * @param add the number of character which are inserted or overwriting at <code>offset</code> */ private void adjustGap(int offset, int remove, int add) { final int oldGapSize= gapSize(); final int newGapSize= oldGapSize - add + remove; final boolean reuseArray= 0 <= newGapSize && newGapSize <= fThreshold; final int newGapStart= offset + add; final int newGapEnd; if (reuseArray) newGapEnd= moveGap(offset, remove, oldGapSize, newGapSize, newGapStart); else newGapEnd= reallocate(offset, remove, oldGapSize, newGapSize, newGapStart); fGapStart= newGapStart; fGapEnd= newGapEnd; }