public class

TextPartUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.output.text.TextPartUtil

Class Overview

Class containing utility methods to operate on parts of text documents.

Summary

Nested Classes
class TextPartUtil.LineInfo Information about a line of a text document's part. 
Public Constructors
TextPartUtil()
Public Methods
static String buildRawTextFromPart(ITextDocumentPart part)
Build the textual representation of a part.
static String buildRawTextFromPartInterruptibly(ITextDocumentPart part)
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 getFirstAnchor(ITextDocumentPart part)
Determine the first anchor of the provided part.
static long getFirstAnchorId(ITextDocumentPart part)
Determine the id of the first anchor of the provided part.
static ITextItem getItemAt(ILine line, int offset)
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.
static List<ITextItem> getItems(ITextDocumentPart part)
Retrieve all items of a part.
static IAnchor getLastAnchor(ITextDocumentPart part)
Determine the last inclusive anchor of the provided part.
static long getLastAnchorId(ITextDocumentPart part)
Determine the id of the last anchor of the provided part.
static ILine getLineAt(ITextDocumentPart part, ICoordinates coord)
static List<? extends ILine> 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 getNextAnchorId(ITextDocumentPart part)
Determine the id of the first anchor of the next (contiguous, possibly virtual) part.
static List<Object> 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> iterateLines(ITextDocumentPart part)
Generate an iterable 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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public TextPartUtil ()

Public Methods

public static String buildRawTextFromPart (ITextDocumentPart part)

Build the textual representation of a part.

Parameters
part the part
Returns
  • a string

public static String buildRawTextFromPartInterruptibly (ITextDocumentPart part)

Build the textual representation of a part. This routine throws InterruptedException if the executing thread is interrupted.

Parameters
part the part
Returns
  • a string
Throws
InterruptedException if the executing thread is interrupted.

public static int coordinatesToLineIndex (ITextDocumentPart part, ICoordinates coord)

Compute the part-relative index of a line given its coordinates.

Parameters
part the part
coord 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

public static IAnchor getAnchorAtLine (ITextDocumentPart part, int lineIndex)

Retrieve the document anchor at the provided line.

Parameters
lineIndex a line index within the part
Returns
  • the closest anchor or null

public static IAnchor getAnchorById (ITextDocumentPart part, long anchorId)

Get the anchor that has the exact provided id.

Parameters
part the part
anchorId the anchor identifier
Returns
  • the anchor whose id is the provided "anchor id", or null

public 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). The neighbor is determined by the `mode` parameter.

Parameters
part the part
anchorId the requested anchor identifier
mode 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)

public static IAnchor getFirstAnchor (ITextDocumentPart part)

Determine the first anchor of the provided part.

Parameters
part a part
Returns
  • the first anchor, null on error

public static long getFirstAnchorId (ITextDocumentPart part)

Determine the id of the first anchor of the provided part.

Parameters
part a part
Returns
  • the id, -1 on error

public static ITextItem getItemAt (ILine line, int offset)

Get the item at the given offset of the given line.

Parameters
line part line object
offset an offset that belongs to the item
Returns
  • the item, null on error

public static ITextItem getItemAt (ITextDocumentPart part, int lineIndex, int offset)

Get the item at the given offset of the given line.

Parameters
part the part
lineIndex a line index within the part
offset an offset that belongs to the item
Returns
  • the item, null on error

public static List<ITextItem> getItems (ITextDocumentPart part)

Retrieve all items of a part.

public static IAnchor getLastAnchor (ITextDocumentPart part)

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

public static long getLastAnchorId (ITextDocumentPart part)

Determine the id of the last anchor of the provided part.

Parameters
part a part
Returns
  • the id, -1 on error

public static ILine getLineAt (ITextDocumentPart part, ICoordinates coord)

public static List<? extends ILine> getLinesOfAnchor (ITextDocumentPart part, long anchorId)

Get the lines that belong to a specific anchor of a text part.

Parameters
part the part
anchorId the anchor
Returns
  • a list of part lines, null on error

public static IAnchor getNearestAnchorById (ITextDocumentPart part, long anchorId)

Get the anchor that has the closest id to the requested id.

Note: usual integer distance calculation takes place.

Parameters
part the part
anchorId the requested anchor identifier
Returns
  • the closest anchor (may be exact, before, or after the requested one)

public static long getNextAnchorId (ITextDocumentPart part)

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

public static List<Object> getObjectsAt (ITextDocumentPart part, int lineIndex, int columnOffset)

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 method getObjectLocations(). This method will return an empty list if nothing was provided in the first place.

public static boolean isAnchorDisplayed (ITextDocumentPart part, long anchorId)

public static boolean isInsidePart (ITextDocumentPart part, ICoordinates coord)

Determine if the provided coordinates are inside a document part.

Parameters
part a part
coord some text coordinates
Returns
  • true if the coordinates are included within the part

public static Iterable<TextPartUtil.LineInfo> iterateLines (ITextDocumentPart part)

Generate an iterable 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

public static void verifyPart (ITextDocumentPart part)

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