Class GapTextStore
- java.lang.Object
-
- org.eclipse.jface.text.GapTextStore
-
- All Implemented Interfaces:
ITextStore
public class GapTextStore extends Object implements ITextStore
Implements a gap managing text store. The gap text store relies on the assumption that consecutive changes to a document are co-located. The start of the gap is always moved to the location of the last change.Performance: Typing-style changes perform in constant time unless re-allocation becomes necessary. Generally, a change that does not cause re-allocation will cause at most one arraycopy operation of a length of about d, where d is the distance from the previous change. Let a(x) be the algorithmic performance of an
arraycopyoperation of the length x, then such a change then performs in O(a(x)), get(int, length) performs in O(a(length)),get(int)in O(1).How frequently the array needs re-allocation is controlled by the constructor parameters.
This class is not intended to be subclassed.
- See Also:
for a copy-on-write text store wrapper- Restriction:
- This class is not intended to be subclassed by clients.
-
-
Constructor Summary
Constructors Constructor Description GapTextStore()Equivalent to new GapTextStore(256, 4096, 0.1f).GapTextStore(int lowWatermark, int highWatermark)Deprecated.useGapTextStore(int, int, float)insteadGapTextStore(int minSize, int maxSize, float maxGapFactor)Creates an empty text store that uses re-allocation thresholds relative to the content length.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description charget(int offset)Returns the character at the specified offset.Stringget(int offset, int length)Returns the text of the specified character range.protected StringgetContentAsString()Returns a copy of the content of this text store.protected intgetGapEndIndex()Returns the end index of the gap managed by this text store.protected intgetGapStartIndex()Returns the start index of the gap managed by this text store.intgetLength()Returns number of characters stored in this text store.voidreplace(int offset, int length, String text)Replaces the specified character range with the given text.voidset(String text)Replace the content of the text store with the given text.
-
-
-
Constructor Detail
-
GapTextStore
@Deprecated public GapTextStore(int lowWatermark, int highWatermark)
Deprecated.useGapTextStore(int, int, float)insteadCreates a new empty text store using the specified low and high watermarks.- Parameters:
lowWatermark- unused - at the lower bound, the array is only resized when the content does not fithighWatermark- if the gap is ever larger than this, it will automatically be shrunken (>= 0)
-
GapTextStore
public GapTextStore()
Equivalent to new GapTextStore(256, 4096, 0.1f).- Since:
- 3.3
-
GapTextStore
public GapTextStore(int minSize, int maxSize, float maxGapFactor)Creates an empty text store that uses re-allocation thresholds relative to the content length. Re-allocation is controlled by the gap factor, which is the quotient of the gap size and the array size. Re-allocation occurs if a change causes the gap factor to go outside[0, maxGapFactor]. When re-allocation occurs, the array is sized such that the gap factor is0.5 * maxGapFactor. The gap size computed in this manner is bounded by theminSizeandmaxSizeparameters.A
maxGapFactorof0creates a text store that never has a gap at all (ifminSizeis 0); amaxGapFactorof1creates a text store that doubles its size with every re-allocation and that never shrinks.The
minSizeandmaxSizeparameters are absolute bounds to the allocated gap size. UseminSizeto avoid frequent re-allocation for small documents. UsemaxSizeto avoid a huge gap being allocated for large documents.- Parameters:
minSize- the minimum gap size to allocate (>= 0; use 0 for no minimum)maxSize- the maximum gap size to allocate (>= minSize; useInteger.MAX_VALUEfor no maximum)maxGapFactor- is the maximum fraction of the array that is occupied by the gap (0 <= maxGapFactor <= 1)- Since:
- 3.3
-
-
Method Detail
-
get
public final char get(int offset)
Description copied from interface:ITextStoreReturns the character at the specified offset.- Specified by:
getin interfaceITextStore- Parameters:
offset- the offset in this text store- Returns:
- the character at this offset
-
get
public final String get(int offset, int length)
Description copied from interface:ITextStoreReturns the text of the specified character range.- Specified by:
getin interfaceITextStore- Parameters:
offset- the offset of the rangelength- the length of the range- Returns:
- the text of the range
-
getLength
public final int getLength()
Description copied from interface:ITextStoreReturns number of characters stored in this text store.- Specified by:
getLengthin interfaceITextStore- Returns:
- the number of characters stored in this text store
-
set
public final void set(String text)
Description copied from interface:ITextStoreReplace the content of the text store with the given text. Convenience method forreplace(0, getLength(), text.- Specified by:
setin interfaceITextStore- Parameters:
text- the new content of the text store
-
replace
public final void replace(int offset, int length, String text)Description copied from interface:ITextStoreReplaces the specified character range with the given text.replace(getLength(), 0, "some text")is a valid call and appends text to the end of the text store.- Specified by:
replacein interfaceITextStore- Parameters:
offset- the offset of the range to be replacedlength- the number of characters to be replacedtext- the substitution text
-
getContentAsString
protected String getContentAsString()
Returns a copy of the content of this text store. For internal use only.- Returns:
- a copy of the content of this text store
-
getGapStartIndex
protected int getGapStartIndex()
Returns the start index of the gap managed by this text store. For internal use only.- Returns:
- the start index of the gap managed by this text store
-
getGapEndIndex
protected int getGapEndIndex()
Returns the end index of the gap managed by this text store. For internal use only.- Returns:
- the end index of the gap managed by this text store
-
-