Class CellRegion

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    PasteCellRegion

    public class CellRegion
    extends Object
    implements Serializable
    An immutable object that represents a block of cells with 4 indexes which are first and last row index, first and last column index. It doesn't relate to a sheet. You can use it to compare with another cell region, like diff(), equals(), contains(), or overlaps(). These methods compare 2 regions by their 4 indexes.
    Since:
    3.5.0
    Author:
    dennis
    See Also:
    Serialized Form
    • Field Detail

      • row

        public final int row
      • column

        public final int column
      • lastRow

        public final int lastRow
      • lastColumn

        public final int lastColumn
    • Constructor Detail

      • CellRegion

        public CellRegion​(int row,
                          int column)
        Create a region which only contains 1 cell.
      • CellRegion

        public CellRegion​(String areaReference)
        create a region with cell reference, e.g. "A1:B2"
      • CellRegion

        public CellRegion​(int row,
                          int column,
                          int lastRow,
                          int lastColumn)
        Create a region with 4 indexes
    • Method Detail

      • getReferenceString

        public String getReferenceString()
        Returns:
        a cell reference string it might be A1:B2 for multiple cells or A1 for one cell.
      • isSingle

        public boolean isSingle()
        Returns:
        return TRUE if this region only contains 1 cell, otherwise returns FALSE
      • contains

        public boolean contains​(int row,
                                int column)
        Returns:
        returns TRUE if this region contains (or equals to) the cell specified by row and column index, otherwise returns FALSE
      • contains

        public boolean contains​(CellRegion region)
        Returns:
        returns TRUE if this region contains (or equals to) specified region, otherwise returns FALSE
      • overlaps

        public boolean overlaps​(CellRegion region)
        Returns:
        returns TRUE if this region overlaps specified region, otherwise returns FALSE
      • equals

        public boolean equals​(int row,
                              int column,
                              int lastRow,
                              int lastColumn)
        Returns:
        returns TRUE if this region refers to the same scope as specified region, otherwise returns FALSE
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getRow

        public int getRow()
        Returns:
        first row index
      • getColumn

        public int getColumn()
        Returns:
        first column index
      • getLastRow

        public int getLastRow()
      • getLastColumn

        public int getLastColumn()
      • getRowCount

        public int getRowCount()
      • getColumnCount

        public int getColumnCount()
      • convertIndexToColumnString

        public static String convertIndexToColumnString​(int columnIdx)
      • convertColumnStringToIndex

        public static int convertColumnStringToIndex​(String colRef)
      • diff

        public List<CellRegion> diff​(CellRegion target)
        Returns:
        returns a list of regions that exclude the part which overlaps this region. If this region's area equals to specified region, returned list contains nothing.
      • getOverlap

        public CellRegion getOverlap​(CellRegion target)
        Returns:
        returns the overlapping region between this region and the specified region; null if no overlapping.
      • getCellCount

        public int getCellCount()
        Returns:
        returns the cell count which this region covers
      • cloneCellRegion

        public CellRegion cloneCellRegion()