Class TextGrid

  • Direct Known Subclasses:
    GridPattern

    public class TextGrid
    extends Object
    Author:
    Efstathios Sideris
    • Constructor Detail

      • TextGrid

        public TextGrid()
      • TextGrid

        public TextGrid​(int width,
                        int height)
      • TextGrid

        public TextGrid​(TextGrid otherGrid)
    • Method Detail

      • clear

        public void clear()
      • get

        public char get​(int x,
                        int y)
      • getSubGrid

        public TextGrid getSubGrid​(int x,
                                   int y,
                                   int width,
                                   int height)
      • getStringAt

        public String getStringAt​(int x,
                                  int y,
                                  int length)
      • getNorthOf

        public char getNorthOf​(int x,
                               int y)
      • getSouthOf

        public char getSouthOf​(int x,
                               int y)
      • getEastOf

        public char getEastOf​(int x,
                              int y)
      • getWestOf

        public char getWestOf​(int x,
                              int y)
      • writeStringTo

        public void writeStringTo​(int x,
                                  int y,
                                  String str)
      • set

        public void set​(int x,
                        int y,
                        char c)
      • setRow

        public void setRow​(int y,
                           String row)
      • getWidth

        public int getWidth()
      • getHeight

        public int getHeight()
      • printDebug

        public void printDebug()
      • getDebugString

        public String getDebugString()
      • add

        public boolean add​(TextGrid grid)
        Adds grid to this. Space characters in this grid are replaced with the corresponding contents of grid, otherwise the contents are unchanged.
        Parameters:
        grid -
        Returns:
        false if the grids are of different size
      • replaceTypeOnLine

        public void replaceTypeOnLine()
        Replaces letters or numbers that are on horizontal or vertical lines, with the appropriate character that will make the line continuous (| for vertical and - for horizontal lines)
      • replacePointMarkersOnLine

        public void replacePointMarkersOnLine()
      • getPointMarkersOnLine

        public CellSet getPointMarkersOnLine()
      • replaceHumanColorCodes

        public void replaceHumanColorCodes()
      • replaceAll

        public void replaceAll​(char c1,
                               char c2)
        Replace all occurences of c1 with c2
        Parameters:
        c1 -
        c2 -
      • hasBlankCells

        public boolean hasBlankCells()
      • getAllNonBlank

        public CellSet getAllNonBlank()
      • getAllBoundaries

        public CellSet getAllBoundaries()
      • getAllBlanksBetweenCharacters

        public CellSet getAllBlanksBetweenCharacters()
      • findStrings

        public ArrayList<TextGrid.CellStringPair> findStrings()
        Returns an ArrayList of CellStringPairs that represents all the continuous (non-blank) Strings in the grid. Used on buffers that contain only type, in order to find the positions and the contents of the strings.
        Returns:
      • hasEntryPoint

        public boolean hasEntryPoint​(TextGrid.Cell cell,
                                     int entryPointId)
        This is done in a bit of a messy way, should be impossible to go out of sync with corresponding GridPatternGroup.
        Parameters:
        cell -
        entryPointId -
        Returns:
      • isBlankBetweenCharacters

        public boolean isBlankBetweenCharacters​(TextGrid.Cell cell)
        true if cell is blank and the east and west cells are not (used to find gaps between words)
        Parameters:
        cell -
        Returns:
      • removeNonText

        public void removeNonText()
        Makes blank all the cells that contain non-text elements.
      • removeArrowheads

        public void removeArrowheads()
      • removeColorCodes

        public void removeColorCodes()
      • removeBoundaries

        public void removeBoundaries()
      • findArrowheads

        public ArrayList findArrowheads()
      • removeMarkupTags

        public void removeMarkupTags()
      • matches

        public boolean matches​(GridPattern criteria)
      • isOnHorizontalLine

        public boolean isOnHorizontalLine​(TextGrid.Cell cell)
      • isOnVerticalLine

        public boolean isOnVerticalLine​(TextGrid.Cell cell)
      • isBoundary

        public static boolean isBoundary​(char c)
      • isBoundary

        public boolean isBoundary​(int x,
                                  int y)
      • isHorizontalLine

        public static boolean isHorizontalLine​(char c)
      • isHorizontalLine

        public boolean isHorizontalLine​(TextGrid.Cell cell)
      • isHorizontalLine

        public boolean isHorizontalLine​(int x,
                                        int y)
      • isVerticalLine

        public static boolean isVerticalLine​(char c)
      • isVerticalLine

        public boolean isVerticalLine​(TextGrid.Cell cell)
      • isVerticalLine

        public boolean isVerticalLine​(int x,
                                      int y)
      • isLinesEnd

        public boolean isLinesEnd​(int x,
                                  int y)
      • isLinesEnd

        public boolean isLinesEnd​(TextGrid.Cell cell)
        Stubs are also considered end of lines
        Parameters:
        cell -
        Returns:
      • isVerticalLinesEnd

        public boolean isVerticalLinesEnd​(TextGrid.Cell cell)
      • isHorizontalLinesEnd

        public boolean isHorizontalLinesEnd​(TextGrid.Cell cell)
      • isPointCell

        public boolean isPointCell​(TextGrid.Cell cell)
      • containsAtLeastOneDashedLine

        public boolean containsAtLeastOneDashedLine​(CellSet set)
      • exactlyOneNeighbourIsBoundary

        public boolean exactlyOneNeighbourIsBoundary​(TextGrid.Cell cell)
      • isStub

        public boolean isStub​(TextGrid.Cell cell)
        A stub looks like that:
         
         +- or -+ or + or + or /- or -/ or / (you get the point)
                     |    |                |
         
         
        Parameters:
        cell -
        Returns:
      • isCrossOnLine

        public boolean isCrossOnLine​(TextGrid.Cell cell)
      • isHorizontalCrossOnLine

        public boolean isHorizontalCrossOnLine​(TextGrid.Cell cell)
      • isVerticalCrossOnLine

        public boolean isVerticalCrossOnLine​(TextGrid.Cell cell)
      • isStarOnLine

        public boolean isStarOnLine​(TextGrid.Cell cell)
      • isLoneDiagonal

        public boolean isLoneDiagonal​(TextGrid.Cell cell)
      • isHorizontalStarOnLine

        public boolean isHorizontalStarOnLine​(TextGrid.Cell cell)
      • isVerticalStarOnLine

        public boolean isVerticalStarOnLine​(TextGrid.Cell cell)
      • isArrowhead

        public boolean isArrowhead​(TextGrid.Cell cell)
      • isNorthArrowhead

        public boolean isNorthArrowhead​(TextGrid.Cell cell)
      • isEastArrowhead

        public boolean isEastArrowhead​(TextGrid.Cell cell)
      • isWestArrowhead

        public boolean isWestArrowhead​(TextGrid.Cell cell)
      • isSouthArrowhead

        public boolean isSouthArrowhead​(TextGrid.Cell cell)
      • isBullet

        public boolean isBullet​(int x,
                                int y)
      • replaceBullets

        public void replaceBullets()
      • isStringsStart

        public boolean isStringsStart​(TextGrid.Cell cell)
        true if the cell is not blank but the previous (west) is
        Parameters:
        cell -
        Returns:
      • isStringsEnd

        public boolean isStringsEnd​(TextGrid.Cell cell)
        true if the cell is not blank but the next (east) is
        Parameters:
        cell -
        Returns:
      • otherStringsStartInTheSameColumn

        public int otherStringsStartInTheSameColumn​(TextGrid.Cell cell)
      • otherStringsEndInTheSameColumn

        public int otherStringsEndInTheSameColumn​(TextGrid.Cell cell)
      • isColumnBlank

        public boolean isColumnBlank​(int x)
      • followLine

        public CellSet followLine​(int x,
                                  int y)
      • followLine

        public CellSet followLine​(TextGrid.Cell cell)
        Returns the neighbours of a line-cell that are boundaries (0 to 2 cells are returned)
        Parameters:
        cell -
        Returns:
        null if the cell is not a line
      • isOutOfBounds

        public boolean isOutOfBounds​(TextGrid.Cell cell)
      • isOutOfBounds

        public boolean isOutOfBounds​(int x,
                                     int y)
      • isBlank

        public boolean isBlank​(int x,
                               int y)
      • isCorner

        public boolean isCorner​(int x,
                                int y)
      • isNormalCorner

        public boolean isNormalCorner​(TextGrid.Cell cell)
      • isNormalCorner

        public boolean isNormalCorner​(int x,
                                      int y)
      • isRoundCorner

        public boolean isRoundCorner​(TextGrid.Cell cell)
      • isRoundCorner

        public boolean isRoundCorner​(int x,
                                     int y)
      • isIntersection

        public boolean isIntersection​(TextGrid.Cell cell)
      • isIntersection

        public boolean isIntersection​(int x,
                                      int y)
      • equals

        public boolean equals​(TextGrid grid)
      • fillCellsWith

        public void fillCellsWith​(Iterable cells,
                                  char c)
        Fills all the cells in cells with c
        Parameters:
        cells -
        c -
      • fillContinuousArea

        public CellSet fillContinuousArea​(int x,
                                          int y,
                                          char c)
      • findBoundariesExpandingFrom

        public CellSet findBoundariesExpandingFrom​(TextGrid.Cell seed)
        Locates and returns the '*' boundaries that we would encounter if we did a flood-fill at seed.
        Parameters:
        seed -
        Returns:
      • cellContainsDashedLineChar

        public boolean cellContainsDashedLineChar​(TextGrid.Cell cell)