# Interface: com.pnfsoftware.jeb.core.output.text.ITextDocument

A text document is used to represent arbitrarily long buffers of interactive text data. A document is indexed by [anchors](IAnchor). A document may have up to 2^63 anchors. A document can be seen as a partition of one or more non\-overlapping, disjoint chunks containing 1 or more [line](ILine) \(or one or more anchored blocks\). Those chunks are represented by [parts](ITextDocumentPart). The first line of a chunk is called the anchor line, or anchor. 

 Classes implementing this interface should also support an optional [coordinates](ICoordinates) \-to\-address \(and vice\-versa\) addressing system, to offer front\-ends the capability to let clients know where they are in a text document.

## Method: addressToCoordinates
- parameter: `address`, type: `java.lang.String`
- return type: `com.pnfsoftware.jeb.core.output.text.ICoordinates`

Description: Convert a unit\-specific address to document\-specific text coordinates. It is recommended to return canonical coordinates. The implementation might return approximate coordinates, ie the closest coordinates \(in terms of distance\) calculated as part of a best effort approach to minimize the return of null values. 

 Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.
parameter: address: a textual address
return: the text coordinates, null on error

## Method: addressToCoordinates
- parameter: `address`, type: `java.lang.String`
- parameter: `precision`, type: `com.pnfsoftware.jeb.core.output.CoordinatesConversionPrecision`
- return type: `com.pnfsoftware.jeb.core.output.text.ICoordinates`

Description: Convert a unit\-specific address to document\-specific text coordinates. It is recommended to return canonical coordinates. The implementation might return approximate coordinates, ie the closest coordinates \(in terms of distance\) calculated as part of a best effort approach to minimize the return of null values. 

 Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.
parameter: address: a textual address
parameter: precision: requested conversion strategy
return: the text coordinates, null on error

## Method: coordinatesToAddress
- parameter: `coordinates`, type: `com.pnfsoftware.jeb.core.output.text.ICoordinates`
- return type: `java.lang.String`

Description: Convert document\-specific text coordinates to a unit\-specific address using a default conversion precision. 

 Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.
parameter: coordinates: the coordinates
return: the address, null on error

## Method: coordinatesToAddress
- parameter: `coordinates`, type: `com.pnfsoftware.jeb.core.output.text.ICoordinates`
- parameter: `precision`, type: `com.pnfsoftware.jeb.core.output.AddressConversionPrecision`
- return type: `java.lang.String`

Description: Convert document\-specific text coordinates to a unit\-specific address. 

 Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.
parameter: coordinates: the coordinates
parameter: precision: indicate the precision of the address \(            [AddressConversionPrecision#COARSE](AddressConversionPrecision#COARSE) will return a raw address, with a faster            result while [AddressConversionPrecision#FINE](AddressConversionPrecision#FINE) will return a more precise            address that can be a bit longer\). If [AddressConversionPrecision#COARSE](AddressConversionPrecision#COARSE)            can not be retrieved, it may return a null result, and the user will need to            recall this method with another precision.
return: the address, null on error

## Method: format
- return type: `java.lang.String`

Description: Format this text document.
return: the formatted textual contents of the document

## Method: getAnchorCount
- return type: `long`

Description: Get the range of anchor points in the document. Returning 1 means that the document returns a single part, holding the entire contents. 

 Note that the anchor at "[#getFirstAnchor()](#getFirstAnchor()) \+ [#getAnchorCount()](#getAnchorCount())" is the "end" anchor \(one after the last\), and lies outside the document. It is not a valid anchor.
return: the count/range of anchors in this document, must be greater than zero

## Method: getBinaryRepresentation
- return type: `com.pnfsoftware.jeb.core.output.text.IBinaryRepresentation`

Description: Retrieve a binary representation of this document. Implementation is optional; implementers may return null.
return: the binary representation, or `null` if unsupported

## Method: getDocumentPart
- parameter: `anchorId`, type: `long`
- parameter: `linesAfter`, type: `int`
- parameter: `linesBefore`, type: `int`
- return type: `com.pnfsoftware.jeb.core.output.text.ITextDocumentPart`

Description: Retrieve a document part. Clients call this method to retrieve a document part starting at a specific anchor, and containing the given amount of lines after and before the anchor. It is the responsibility of the implementor to sanitize the input \(eg, negative number of lines, invalid anchor, etc.\) and provide appropriate response \(eg, truncating\). It is recommended that implementors try not to raise an exception on error. In the worst case scenario, an empty document can be returned.
parameter: anchorId: the anchor identifier
parameter: linesAfter: hint lines count to return after the given anchor, could be more or less
parameter: linesBefore: hint lines count to return before the given anchor, could be more or less
return: a document part containing as many anchors as required to honor the client requests.         If linesAfter is non\-null, the first anchor within the document part may not be         anchorId, but one anchor before that. This method should return null if an invalid         anchor was provided

## Method: getDocumentPart
- parameter: `anchorId`, type: `long`
- parameter: `linesAfter`, type: `int`
- return type: `com.pnfsoftware.jeb.core.output.text.ITextDocumentPart`

Description: Retrieve a document part. Equivalent to [getDocumentPart\(anchorId, linesAfter\)](#getDocumentPart(long, int)) .
parameter: anchorId: the anchor id
parameter: linesAfter: number of lines after
return: the document part

## Method: getDocumentPart2
- parameter: `anchorBegin`, type: `long`
- parameter: `anchorEnd`, type: `long`
- return type: `com.pnfsoftware.jeb.core.output.text.ITextDocumentPart`

Description: Retrieve the document part located between two anchor references. This method is optional.
parameter: anchorBegin: start anchor, inclusive
parameter: anchorEnd: final anchor, exclusive
return: the document part
throws: implementations should throw if this method is not             implemented

## Method: getFirstAnchor
- return type: `long`

Description: Get the first anchor identifier of the document. Most document will want to have 0 as their first anchor identifier.
return: an integer greater or equal than zero

## Method: getInitialAnchor
- return type: `long`

Description: Get the anchor identifier that would represent the first logical section of a document \(meaning the anchor to focus on when opening a document\). If not specified, the first anchor is considered to be the initial anchor.
return: an integer, 0 if not specified

## Method: hasBinaryRepresentation
- return type: `boolean`

Description: Determine if this document offers binary representations. If this method returns true, [#getBinaryRepresentation()](#getBinaryRepresentation()) may be safely called and shall return a non\-null object.
return: `true` if a binary representation is available

