Class TextPartUtil
java.lang.Object
com.pnfsoftware.jeb.core.output.text.TextPartUtil
Class containing utility methods to operate on parts of text documents.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Information about a line of a text document's part. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Build the textual representation of a part.static String
Build the textual representation of a part.static int
coordinatesToLineIndex
(ITextDocumentPart part, ICoordinates coord) Compute the part-relative index of a line given its coordinates.static IAnchor
getAnchorAtLine
(ITextDocumentPart part, int lineIndex) Retrieve the document anchor at the provided line.static IAnchor
getAnchorById
(ITextDocumentPart part, long anchorId) Get the anchor that has the exact provided id.static IAnchor
getApproximateAnchorById
(ITextDocumentPart part, long anchorId, int mode) Get the anchor that has the provided id, or if none is found, one if its neighbor (not necessarily the closest neighbor).static IAnchor
Determine the first anchor of the provided part.static long
Determine the id of the first anchor of the provided part.static ITextItem
Get the item at the given offset of the given line.static ITextItem
getItemAt
(ITextDocumentPart part, int lineIndex, int offset) Get the item at the given offset of the given line.getItems
(ITextDocumentPart part) Retrieve all items of a part.static IAnchor
Determine the last inclusive anchor of the provided part.static long
Determine the id of the last anchor of the provided part.static ILine
getLineAt
(ITextDocumentPart part, ICoordinates coord) getLinesOfAnchor
(ITextDocumentPart part, long anchorId) Get the lines that belong to a specific anchor of a text part.static IAnchor
getNearestAnchorById
(ITextDocumentPart part, long anchorId) Get the anchor that has the closest id to the requested id.static long
Determine the id of the first anchor of the next (contiguous, possibly virtual) part.getObjectsAt
(ITextDocumentPart part, int lineIndex, int columnOffset) Retrieve the list of objects whose representations fall onto the provided coordinates, within a part.static boolean
isAnchorDisplayed
(ITextDocumentPart part, long anchorId) static boolean
isInsidePart
(ITextDocumentPart part, ICoordinates coord) Determine if the provided coordinates are inside a document part.static Iterable<TextPartUtil.LineInfo>
Generate aniterable
object for easy iteration over the lines (and their associated anchor id, and line numbers) of a part.static void
verifyPart
(ITextDocumentPart part) Verify the partial correctness of a part.
-
Constructor Details
-
TextPartUtil
public TextPartUtil()
-
-
Method Details
-
verifyPart
Verify the partial correctness of a part. A correct part will pass this test; however, passing this test does not mean the part is correct.- Parameters:
part
- the part to be tested
-
getFirstAnchor
Determine the first anchor of the provided part.- Parameters:
part
- a part- Returns:
- the first anchor, null on error
-
getFirstAnchorId
Determine the id of the first anchor of the provided part.- Parameters:
part
- a part- Returns:
- the id, -1 on error
-
getLastAnchor
Determine the last inclusive anchor of the provided part. The returned anchor is guaranteed to reference lines that are in the document part.- Parameters:
part
- a part- Returns:
- the last anchor, null on error
-
getLastAnchorId
Determine the id of the last anchor of the provided part.- Parameters:
part
- a part- Returns:
- the id, -1 on error
-
getNextAnchorId
Determine the id of the first anchor of the next (contiguous, possibly virtual) part.- Parameters:
part
- the current part- Returns:
- the next anchor id, -1 on error
-
getItems
Retrieve all items of a part.- Parameters:
part
-- Returns:
-
getItemAt
Get the item at the given offset of the given line.- Parameters:
part
- the partlineIndex
- a line index within the partoffset
- an offset that belongs to the item- Returns:
- the item, null on error
-
getItemAt
Get the item at the given offset of the given line.- Parameters:
line
- part line objectoffset
- an offset that belongs to the item- Returns:
- the item, null on error
-
buildRawTextFromPart
Build the textual representation of a part.- Parameters:
part
- the part- Returns:
- a string
-
buildRawTextFromPartInterruptibly
public static String buildRawTextFromPartInterruptibly(ITextDocumentPart part) throws InterruptedException Build the textual representation of a part. This routine throwsInterruptedException
if the executing thread is interrupted.- Parameters:
part
- the part- Returns:
- a string
- Throws:
InterruptedException
- if the executing thread is interrupted.
-
getLinesOfAnchor
Get the lines that belong to a specific anchor of a text part.- Parameters:
part
- the partanchorId
- the anchor- Returns:
- a list of part lines, null on error
-
getLineAt
-
getAnchorAtLine
Retrieve the document anchor at the provided line.- Parameters:
lineIndex
- a line index within the part- Returns:
- the closest anchor or null
-
isInsidePart
Determine if the provided coordinates are inside a document part.- Parameters:
part
- a partcoord
- some text coordinates- Returns:
- true if the coordinates are included within the part
-
coordinatesToLineIndex
Compute the part-relative index of a line given its coordinates.- Parameters:
part
- the partcoord
- some coordinates- Returns:
- the line index, or -1 if the provided coordinates are outside the part or cannot be mapped to text located in the part
-
getAnchorById
Get the anchor that has the exact provided id.- Parameters:
part
- the partanchorId
- the anchor identifier- Returns:
- the anchor whose id is the provided
"anchor id"
, or null
-
getNearestAnchorById
Get the anchor that has the closest id to the requested id.Note: usual integer distance calculation takes place.
- Parameters:
part
- the partanchorId
- the requested anchor identifier- Returns:
- the closest anchor (may be exact, before, or after the requested one)
-
getApproximateAnchorById
Get the anchor that has the provided id, or if none is found, one if its neighbor (not necessarily the closest neighbor). The neighbor is determined by the `mode` parameter.- Parameters:
part
- the partanchorId
- the requested anchor identifiermode
- in effect only if no exact anchor was found - 0= nearest neighbor; 1= the right nearest neighbor; -1: the left nearest neighbor- Returns:
- the proximity anchor, null if no suitable anchor was found (eg, going out of bound)
-
isAnchorDisplayed
-
getObjectsAt
Retrieve the list of objects whose representations fall onto the provided coordinates, within a part. Note that objects and their locations are provided by the optional methodITextDocumentPart.getObjectLocations()
. This method will return an empty list if nothing was provided in the first place.- Parameters:
part
-lineIndex
-columnOffset
-- Returns:
-
iterateLines
Generate aniterable
object for easy iteration over the lines (and their associated anchor id, and line numbers) of a part. Easy to use in a for-loop.- Parameters:
part
- a part- Returns:
- an iterable providing
TextPartUtil.LineInfo
objects
-