@Override public final char get(int offset) { if (offset < fGapStart) return fContent[offset]; return fContent[offset + gapSize()]; }
@Override public final char get(int offset) { if (offset < fGapStart) return fContent[offset]; return fContent[offset + gapSize()]; }
@Override public final int getLength() { return fContent.length - gapSize(); }
@Override public final int getLength() { return fContent.length - gapSize(); }
@Override public final String get(int offset, int length) { if (fGapStart <= offset) return new String(fContent, offset + gapSize() , length); final int end= offset + length; if (end <= fGapStart) return new String(fContent, offset, length); StringBuilder buf= new StringBuilder(length); // see Bug 113871 buf.append(fContent, offset, fGapStart - offset); buf.append(fContent, fGapEnd, end - fGapStart); return buf.toString(); }
@Override public final String get(int offset, int length) { if (fGapStart <= offset) return new String(fContent, offset + gapSize() , length); final int end= offset + length; if (end <= fGapStart) return new String(fContent, offset, length); StringBuffer buf= new StringBuffer(length); buf.append(fContent, offset, fGapStart - offset); buf.append(fContent, fGapEnd, end - fGapStart); return buf.toString(); }
/** * 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; }