Class DocumentFile

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Document

    public class DocumentFile
    extends Object
    implements Document, Closeable
    Implementation that handles a Document as a file in the filesystem and receives operations in a sorted manner (i.e. the regions are sorted). This improves the efficiency of reading the file by only scanning it once while operations are applied, until an instance of this document is closed.
    • Method Detail

      • insert

        public void insert​(int beginLine,
                           int beginColumn,
                           String textToInsert)
        Description copied from interface: Document
        Insert a text at a line at the position/column specified. If there is any text to the right of the insertion, that text is shifted by the length of the text to insert, which means that it is not replaced.
        Specified by:
        insert in interface Document
        Parameters:
        beginLine - the line in which to insert the text
        beginColumn - the position in the line in which to insert the text
        textToInsert - the text to be added
      • replace

        public void replace​(RegionByLine regionByLine,
                            String textToReplace)
        Description copied from interface: Document
        Replace a specific region in the document which contains text by another text, which not necessarily is the same length as the region's one.
        Specified by:
        replace in interface Document
        Parameters:
        regionByLine - the region in which a text will be inserted to replace the current document's contents
        textToReplace - the text to insert
      • delete

        public void delete​(RegionByLine regionByOffset)
        Description copied from interface: Document
        Delete a region in the document, removing all text which contains it. If there is any text to the right of this region, it will be shifted to the left by the length of the region to delete.
        Specified by:
        delete in interface Document
        Parameters:
        regionByOffset - the region in which to erase all the text