Class FastPartitioner
- All Implemented Interfaces:
- IDocumentPartitioner,- IDocumentPartitionerExtension,- IDocumentPartitionerExtension2,- IDocumentPartitionerExtension3
IPartitionTokenScanner to scan the document and to determine the
 document's partitioning. The tokens returned by the scanner must return the
 partition type as their data. The partitioner remembers the document's
 partitions in the document itself rather than maintaining its own data
 structure.
 
 To reduce array creations in IDocument.getPositions(String), the
 positions get cached. The cache is cleared after updating the positions in
 documentChanged2(DocumentEvent). Subclasses need to call
 clearPositionCache() after modifying the partitioner's positions.
 The cached positions may be accessed through getPositions().
 
- Since:
- 3.14
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected intThe offset at which a partition has been deletedprotected IDocumentThe partitioner's documentprotected intThe offset at which the last changed partition endsprotected final String[]The legal content types of this partitionerprotected final DefaultPositionUpdaterThe position updater used to for the default updating of partitionsprotected intThe document length before a document change occurredprotected final IPartitionTokenScannerThe partitioner's scannerprotected intThe offset at which the first changed partition starts
- 
Constructor SummaryConstructorsConstructorDescriptionFastPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) Creates a new partitioner that uses the given scanner and may return partitions of the given legal content types.
- 
Method SummaryModifier and TypeMethodDescriptionprotected final voidCallsinitialize()if the receiver is not yet initialized.protected final voidClears the position cache.final ITypedRegion[]computePartitioning(int offset, int length) Returns the partitioning of the given range of the connected document.computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) Returns the partitioning of the given range of the connected document.final voidConnects the partitioner to a document.voidConnects this partitioner to a document.voidDisconnects the partitioner from the document it is connected to.voidInforms about a forthcoming document change.final booleanThe document has been changed.The document has been changed.protected TypedPositionfindClosestPosition(int offset) Returns the position in the partitoner's position category which is close to the given offset.protected final voidFlushes the active rewrite session.Returns the active rewrite session of this document ornull.getContentType(int offset) Returns the content type of the partition containing the given offset in the connected document.getContentType(int offset, boolean preferOpenPartitions) Returns the content type of the partition containing the given offset in the connected document.String[]Returns the set of all legal content types of this partitioner.String[]Returns the position categories that this partitioners uses in order to manage the partitioning information of the documents.getPartition(int offset) Returns the partition containing the given offset of the connected document.getPartition(int offset, boolean preferOpenPartitions) Returns the partition containing the given offset of the connected document.protected final Position[]Returns the partitioners positions.protected StringgetTokenContentType(IToken token) Returns a content type encoded in the given token.protected voidPerforms the initial partitioning of the partitioner's document.protected booleanisSupportedContentType(String contentType) Returns whether the given type is one of the legal content types.voidTells the document partitioner that a rewrite session started.voidstopRewriteSession(DocumentRewriteSession session) Tells the document partitioner that the rewrite session has finished.
- 
Field Details- 
fScannerThe partitioner's scanner
- 
fLegalContentTypesThe legal content types of this partitioner
- 
fDocumentThe partitioner's document
- 
fPreviousDocumentLengthprotected int fPreviousDocumentLengthThe document length before a document change occurred
- 
fPositionUpdaterThe position updater used to for the default updating of partitions
- 
fStartOffsetprotected int fStartOffsetThe offset at which the first changed partition starts
- 
fEndOffsetprotected int fEndOffsetThe offset at which the last changed partition ends
- 
fDeleteOffsetprotected int fDeleteOffsetThe offset at which a partition has been deleted
 
- 
- 
Constructor Details- 
FastPartitionerCreates a new partitioner that uses the given scanner and may return partitions of the given legal content types.- Parameters:
- scanner- the scanner this partitioner is supposed to use
- legalContentTypes- the legal content types of this partitioner
 
 
- 
- 
Method Details- 
getManagingPositionCategoriesDescription copied from interface:IDocumentPartitionerExtension2Returns the position categories that this partitioners uses in order to manage the partitioning information of the documents. Returnsnullif no position category is used.- Specified by:
- getManagingPositionCategoriesin interface- IDocumentPartitionerExtension2
- Returns:
- the position categories used to manage partitioning information or null
 
- 
connectDescription copied from interface:IDocumentPartitionerConnects the partitioner to a document. Connect indicates the begin of the usage of the receiver as partitioner of the given document. Thus, resources the partitioner needs to be operational for this document should be allocated.The caller of this method must ensure that this partitioner is also set as the document's document partitioner. This method has been replaced with IDocumentPartitionerExtension3.connect(IDocument, boolean). Implementers should default a callconnect(document)toconnect(document, false)in order to sustain the same semantics.- Specified by:
- connectin interface- IDocumentPartitioner
- Parameters:
- document- the document to be connected to
 
- 
connectConnects this partitioner to a document. Connect indicates the begin of the usage of the receiver as partitioner of the given document. Thus, resources the partitioner needs to be operational for this document should be allocated.The caller of this method must ensure that this partitioner is also set as the document's document partitioner. delayInitializationindicates whether the partitioner is allowed to delay it initial computation of the document's partitioning until it has to answer the first query. ReplacesIDocumentPartitioner.connect(IDocument).May be extended by subclasses. - Specified by:
- connectin interface- IDocumentPartitionerExtension3
- Parameters:
- document- the document to be connected to
- delayInitialization-- trueif initialization can be delayed,- falseotherwise
 
- 
checkInitializationprotected final void checkInitialization()Callsinitialize()if the receiver is not yet initialized.
- 
initializeprotected void initialize()Performs the initial partitioning of the partitioner's document.May be extended by subclasses. 
- 
disconnectpublic void disconnect()Disconnects the partitioner from the document it is connected to. Disconnect indicates the end of the usage of the receiver as partitioner of the connected document. Thus, resources the partitioner needed to be operation for its connected document should be deallocated.The caller of this method should also must ensure that this partitioner is no longer the document's partitioner. May be extended by subclasses. - Specified by:
- disconnectin interface- IDocumentPartitioner
 
- 
documentAboutToBeChangedInforms about a forthcoming document change. Will be called by the connected document and is not intended to be used by clients other than the connected document.May be extended by subclasses. - Specified by:
- documentAboutToBeChangedin interface- IDocumentPartitioner
- Parameters:
- e- the event describing the forthcoming change
 
- 
documentChangedDescription copied from interface:IDocumentPartitionerThe document has been changed. The partitioner updates the document's partitioning and returns whether the structure of the document partitioning has been changed, i.e. whether partitions have been added or removed. Will be called by the connected document and is not intended to be used by clients other than the connected document.This method has been replaced by IDocumentPartitionerExtension.documentChanged2(DocumentEvent).- Specified by:
- documentChangedin interface- IDocumentPartitioner
- Parameters:
- e- the event describing the document change
- Returns:
- trueif partitioning changed
 
- 
documentChanged2The document has been changed. The partitioner updates the document's partitioning and returns the minimal region that comprises all partition changes caused in response to the given document event. This method returnsnullif the partitioning did not change.Will be called by the connected document and is not intended to be used by clients other than the connected document. Replaces IDocumentPartitioner.documentChanged(DocumentEvent).May be extended by subclasses. - Specified by:
- documentChanged2in interface- IDocumentPartitionerExtension
- Parameters:
- e- the event describing the document change
- Returns:
- the region of the document in which the partition type changed or null
 
- 
findClosestPositionReturns the position in the partitoner's position category which is close to the given offset. This is, the position has either an offset which is the same as the given offset or an offset which is smaller than the given offset. This method profits from the knowledge that a partitioning is a ordered set of disjoint position.May be extended or replaced by subclasses. - Parameters:
- offset- the offset for which to search the closest position
- Returns:
- the closest position in the partitioner's category
 
- 
getContentTypeReturns the content type of the partition containing the given offset in the connected document. There must be a document connected to this partitioner.Use IDocumentPartitionerExtension2.getContentType(int, boolean)when zero-length partitions are supported. In that case this method is equivalent:IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner; return extension.getContentType(offset, false);May be replaced or extended by subclasses. - Specified by:
- getContentTypein interface- IDocumentPartitioner
- Parameters:
- offset- the offset in the connected document
- Returns:
- the content type of the offset's partition
 
- 
getPartitionReturns the partition containing the given offset of the connected document. There must be a document connected to this partitioner.Use IDocumentPartitionerExtension2.getPartition(int, boolean)when zero-length partitions are supported. In that case this method is equivalent:IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner; return extension.getPartition(offset, false);May be replaced or extended by subclasses. - Specified by:
- getPartitionin interface- IDocumentPartitioner
- Parameters:
- offset- the offset for which to determine the partition
- Returns:
- the partition containing the offset
 
- 
computePartitioningDescription copied from interface:IDocumentPartitionerReturns the partitioning of the given range of the connected document. There must be a document connected to this partitioner.Use IDocumentPartitionerExtension2.computePartitioning(int, int, boolean)when zero-length partitions are supported. In that case this method is equivalent:IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner; return extension.computePartitioning(offset, length, false);- Specified by:
- computePartitioningin interface- IDocumentPartitioner
- Parameters:
- offset- the offset of the range of interest
- length- the length of the range of interest
- Returns:
- the partitioning of the range
 
- 
getLegalContentTypesReturns the set of all legal content types of this partitioner. I.e. any result delivered by this partitioner may not contain a content type which would not be included in this method's result.May be replaced or extended by subclasses. - Specified by:
- getLegalContentTypesin interface- IDocumentPartitioner
- Returns:
- the set of legal content types
 
- 
isSupportedContentTypeReturns whether the given type is one of the legal content types.May be extended by subclasses. - Parameters:
- contentType- the content type to check
- Returns:
- trueif the content type is a legal content type
 
- 
getTokenContentTypeReturns a content type encoded in the given token. If the token's data is notnulland a string it is assumed that it is the encoded content type.May be replaced or extended by subclasses. - Parameters:
- token- the token whose content type is to be determined
- Returns:
- the token's content type
 
- 
getContentTypeReturns the content type of the partition containing the given offset in the connected document. There must be a document connected to this partitioner.If preferOpenPartitionsistrue, precedence is given to an open partition ending atoffsetover a delimited partition starting atoffset.This method replaces IDocumentPartitioner.getContentType(int)and behaves like it whenprepreferOpenPartitionsisfalse, i.e. precedence is always given to the partition that does not end atoffset.May be replaced or extended by subclasses. - Specified by:
- getContentTypein interface- IDocumentPartitionerExtension2
- Parameters:
- offset- the offset in the connected document
- preferOpenPartitions-- trueif precedence should be given to a open partition ending at- offsetover a delimited partition starting at- offset
- Returns:
- the content type of the offset's partition
 
- 
getPartitionReturns the partition containing the given offset of the connected document. There must be a document connected to this partitioner.If preferOpenPartitionsistrue, precedence is given to an open partition ending atoffsetover a delimited partition starting atoffset.This method replaces IDocumentPartitioner.getPartition(int)and behaves like it whenpreferOpenPartitionsisfalse, i.e. precedence is always given to the partition that does not end atoffset.May be replaced or extended by subclasses. - Specified by:
- getPartitionin interface- IDocumentPartitionerExtension2
- Parameters:
- offset- the offset for which to determine the partition
- preferOpenPartitions-- trueif precedence should be given to a open partition ending at- offsetover a delimited partition starting at- offset
- Returns:
- the partition containing the offset
 
- 
computePartitioningpublic ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) Returns the partitioning of the given range of the connected document. There must be a document connected to this partitioner.If includeZeroLengthPartitionsistrue, a zero-length partition of an open partition type (usually the default partition) is included between two delimited partitions. If it isfalse, no zero-length partitions are included.This method replaces IDocumentPartitioner.computePartitioning(int, int)and behaves like it whenincludeZeroLengthPartitionsisfalse.May be replaced or extended by subclasses. - Specified by:
- computePartitioningin interface- IDocumentPartitionerExtension2
- Parameters:
- offset- the offset of the range of interest
- length- the length of the range of interest
- includeZeroLengthPartitions-- trueif zero-length partitions should be returned as part of the computed partitioning
- Returns:
- the partitioning of the range
 
- 
startRewriteSessionDescription copied from interface:IDocumentPartitionerExtension3Tells the document partitioner that a rewrite session started. A rewrite session is a sequence of replace operations that form a semantic unit. The document partitioner is allowed to use that information for internal optimization.- Specified by:
- startRewriteSessionin interface- IDocumentPartitionerExtension3
- Parameters:
- session- the rewrite session
- Throws:
- IllegalStateException- in case there is already an active rewrite session
 
- 
stopRewriteSessionTells the document partitioner that the rewrite session has finished. This method is only called whenstartRewriteSessionhas been called before.May be extended by subclasses. - Specified by:
- stopRewriteSessionin interface- IDocumentPartitionerExtension3
- Parameters:
- session- the rewrite session
 
- 
getActiveRewriteSessionReturns the active rewrite session of this document ornull.May be extended by subclasses. - Specified by:
- getActiveRewriteSessionin interface- IDocumentPartitionerExtension3
- Returns:
- the active rewrite session or null
 
- 
flushRewriteSessionprotected final void flushRewriteSession()Flushes the active rewrite session.
- 
clearPositionCacheprotected final void clearPositionCache()Clears the position cache. Needs to be called whenever the positions have been updated.
- 
getPositionsReturns the partitioners positions.- Returns:
- the partitioners positions
- Throws:
- BadPositionCategoryException- if getting the positions from the document fails
 
 
-