FileDocCategorySizeDatePackage
Region.javaAPI DocApache Poi 3.0.15735Mon Jan 01 12:39:36 GMT 2007org.apache.poi.hssf.util

Region

public class Region extends Object implements Comparable
Represents a from/to row/col square. This is a object primitive that can be used to represent row,col - row,col just as one would use String to represent a string of characters. Its really only useful for HSSF though.
author
Andrew C. Oliver acoliver at apache dot org

Fields Summary
private int
rowFrom
private short
colFrom
private int
rowTo
private short
colTo
Constructors Summary
public Region()
Creates a new instance of Region (0,0 - 0,0)

    
public Region(int rowFrom, short colFrom, int rowTo, short colTo)

        this.rowFrom = rowFrom;
        this.rowTo   = rowTo;
        this.colFrom = colFrom;
        this.colTo   = colTo;
    
public Region(org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion region)
special constructor (I know this is bad but it is so wrong that its right okay) that makes a region from a mergedcells's region subrecord.

        this(region.row_from, region.col_from, region.row_to, region.col_to);
    
Methods Summary
public intcompareTo(org.apache.poi.hssf.util.Region r)
Compares that the given region is the same less than or greater than this region. If any regional coordiant passed in is less than this regions coordinants then a positive integer is returned. Otherwise a negative integer is returned.

param
r region
see
#compareTo(Object)

        if ((this.getRowFrom() == r.getRowFrom())
                && (this.getColumnFrom() == r.getColumnFrom())
                && (this.getRowTo() == r.getRowTo())
                && (this.getColumnTo() == r.getColumnTo()))
        {
            return 0;
        }
        if ((this.getRowFrom() < r.getRowFrom())
                || (this.getColumnFrom() < r.getColumnFrom())
                || (this.getRowTo() < r.getRowTo())
                || (this.getColumnTo() < r.getColumnTo()))
        {
            return 1;
        }
        return -1;
    
public intcompareTo(java.lang.Object o)

        return compareTo(( Region ) o);
    
public booleancontains(int row, short col)
Answers: "is the row/column inside this range?"

return
true if the cell is in the range and false if it is not

        if ((this.rowFrom <= row) && (this.rowTo >= row)
                && (this.colFrom <= col) && (this.colTo >= col))
        {

//                System.out.println("Region ("+rowFrom+","+colFrom+","+rowTo+","+ 
//                                   colTo+") does contain "+row+","+col);
            return true;
        }
        return false;
    
public booleanequals(org.apache.poi.hssf.util.Region r)

        return (compareTo(r) == 0);
    
public intgetArea()

return
the area contained by this region (number of cells)

        return ((1 + (getRowTo() - getRowFrom()))
                * (1 + (getColumnTo() - getColumnFrom())));
    
public shortgetColumnFrom()
get the upper left hand corner column number

return
column number for the upper left hand corner

        return colFrom;
    
public shortgetColumnTo()
get the lower right hand corner column number

return
column number for the lower right hand corner

        return colTo;
    
public intgetRowFrom()
get the upper left hand corner row number

return
row number for the upper left hand corner

        return rowFrom;
    
public intgetRowTo()
get the lower right hand corner row number

return
row number for the lower right hand corner

        return rowTo;
    
public voidsetColumnFrom(short colFrom)
set the upper left hand corner column number

param
colFrom column number for the upper left hand corner

        this.colFrom = colFrom;
    
public voidsetColumnTo(short colTo)
set the lower right hand corner column number

param
colTo column number for the lower right hand corner

        this.colTo = colTo;
    
public voidsetRowFrom(int rowFrom)
set the upper left hand corner row number

param
rowFrom row number for the upper left hand corner

        this.rowFrom = rowFrom;
    
public voidsetRowTo(int rowTo)
get the lower right hand corner row number

param
rowTo row number for the lower right hand corner

        this.rowTo = rowTo;