Class TextPartUtil

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

public class TextPartUtil extends Object
Class containing utility methods to operate on parts of text documents.
  • Constructor Details

    • TextPartUtil

      public TextPartUtil()
  • Method Details

    • verifyPart

      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
    • getFirstAnchor

      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
    • getFirstAnchorId

      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
    • getLastAnchor

      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
    • getLastAnchorId

      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
    • getNextAnchorId

      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
    • getItems

      public static List<ITextItem> getItems(ITextDocumentPart part)
      Retrieve all items of a part.
      Parameters:
      part -
      Returns:
    • getItemAt

      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
    • getItemAt

      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
    • buildRawTextFromPart

      public static String buildRawTextFromPart(ITextDocumentPart part)
      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 throws InterruptedException if the executing thread is interrupted.
      Parameters:
      part - the part
      Returns:
      a string
      Throws:
      InterruptedException - if the executing thread is interrupted.
    • getLinesOfAnchor

      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
    • getLineAt

      public static ILine getLineAt(ITextDocumentPart part, ICoordinates coord)
    • getAnchorAtLine

      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
    • isInsidePart

      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
    • coordinatesToLineIndex

      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
    • getAnchorById

      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
    • getNearestAnchorById

      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)
    • getApproximateAnchorById

      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)
    • isAnchorDisplayed

      public static boolean isAnchorDisplayed(ITextDocumentPart part, long anchorId)
    • getObjectsAt

      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 ITextDocumentPart.getObjectLocations(). This method will return an empty list if nothing was provided in the first place.
      Parameters:
      part -
      lineIndex -
      columnOffset -
      Returns:
    • iterateLines

      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:
      an iterable providing TextPartUtil.LineInfo objects