xelem.3.0

nl.fountain.xelem
Class Address

java.lang.Object
  extended by nl.fountain.xelem.Address
All Implemented Interfaces:
Comparable
Direct Known Subclasses:
CellPointer

public class Address
extends Object
implements Comparable

A reference to the intersection of a row and a column. Besides that Address can be used to get R1C1-reference strings, which can be used in formulas and NamedRanges.


Field Summary
protected  int c
          The column index of this address.
protected  int r
          The row index of this address.
 
Constructor Summary
protected Address()
          This constructor is protected.
  Address(int rowIndex, int columnIndex)
          Constructs a new Address.
  Address(String a1_ref)
          Constructs a new Address.
 
Method Summary
static String calculateColumn(int columnNumber)
          Calculates the column notation in A1-reference style of a given column number.
static int calculateColumn(String s)
          Calculates the column number of a given string in A1-reference style.
static int calculateRow(String s)
          Calculates the row number of a given string in A1-reference style.
 int compareTo(Object o)
          Compare this addres with the specified object for order.
 boolean equals(Object obj)
          Specifies whether the object in the parameter is equal to this address.
 String getA1Reference()
          Translates the position of this address into an A1-reference string.
 String getAbsoluteAddress()
          Translates the position of this address into an absolute R1C1-reference string.
 String getAbsoluteRange(Address otherAddress)
          Gets the absolute range-address of a rectangular range in R1C1-reference style.
static String getAbsoluteRange(Collection<Address> addresses)
          Gets the absolute range-address of a collection of addresses in R1C1-reference style.
 String getAbsoluteRange(int row, int column)
          Gets the absolute range-address of a rectangular range in R1C1-reference style.
 int getColumnIndex()
          Gets the index of the column of this address.
 String getRefTo(Address otherAddress)
          Gets a relative reference from this address to another address in R1C1-reference style.
 String getRefTo(Address address1, Address address2)
          Gets a relative reference from this address to a rectanglular range in R1C1-reference style.
 String getRefTo(Area area)
          Gets a relative reference from this address to an area.
 String getRefTo(Collection<Address> addresses)
          Gets a relative reference from this address to a collection of addresses in R1C1-reference style.
 String getRefTo(int row, int column)
          Gets a relative reference from this address to a cell at the intersection of row and column in R1C1-reference style.
 String getRefTo(int r1, int c1, int r2, int c2)
          Gets a relative reference from this address to a rectanglular range in R1C1-reference style.
 int getRowIndex()
          Gets the index of the row of this address.
 boolean isWithinSheet()
          Specifies whether this address is within the bounds of the spreadsheet.
 String toString()
          Returns a string representation of this address.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

r

protected int r
The row index of this address.


c

protected int c
The column index of this address.

Constructor Detail

Address

protected Address()
This constructor is protected.


Address

public Address(int rowIndex,
               int columnIndex)
Constructs a new Address.

Parameters:
rowIndex - The row index of this Address.
columnIndex - The column index of this Address.

Address

public Address(String a1_ref)
Constructs a new Address. The given string can be of A1-reference style, as used in Excel. The parameter "A1" constructs an address at row 1, column 1; "Z23" leads to an address pointing to row 23, column 26.

This constructor treats the passed string case-insensitive, row indicators (digits) and column indicators (letters) may be intermingled. The next equations all evaluate as true.

   new Address("BQ65").equals(new Address("65bq"))
   new Address("BQ65").equals(new Address("6B5q"))
   etc.
 

Parameters:
a1_ref - a String in A1-reference style
Since:
xelem.2.0
Method Detail

calculateColumn

public static int calculateColumn(String s)
Calculates the column number of a given string in A1-reference style. Column indicator (letters) and row indicator (digits) may be intermingled. Treats the passed string case-insensitive. The maximum column notation that can be calculated is "FXSHRXW" and this string returns Integer.MAX_VALUE. If no letters are present in the given string this method returns 0.

Parameters:
s - a string in A1-reference style
Returns:
the column number of the given string
Since:
xelem.2.0

calculateColumn

public static String calculateColumn(int columnNumber)
Calculates the column notation in A1-reference style of a given column number. A column number of 0 or less returns as an empty string (""). A column number equal to Integer.MAX_VALUE returns "FXSHRXW".

It may be interesting to know that a parameter of 1000 returns "ALL" and that multiplying this parameter with a factor of 676.149 yields the dutch translation: "ALLES". Unfortunately not all words can be translated using the same factor and a more practical use then of this method is to feed it column numbers of 1 to 256 inclusive and get the Excel label of the column, "A" to "IV" inclusive, in return.

Parameters:
columnNumber - the column number to be calculated
Returns:
the column notation in A1-reference style
Since:
xelem.2.0

calculateRow

public static int calculateRow(String s)
Calculates the row number of a given string in A1-reference style. Column indicator (letters) and row indicator (digits) may be intermingled. If no digits are present in the given string this method returns 0.

Parameters:
s - a string in A1-reference style
Returns:
the row number of the given string
Since:
xelem.2.0

getRowIndex

public int getRowIndex()
Gets the index of the row of this address.

Returns:
the index of the row of this address

getColumnIndex

public int getColumnIndex()
Gets the index of the column of this address.

Returns:
the index of the column of this address

isWithinSheet

public boolean isWithinSheet()
Specifies whether this address is within the bounds of the spreadsheet.

Returns:
true if this address is within the bounds of the sheet, false otherwise

getA1Reference

public String getA1Reference()
Translates the position of this address into an A1-reference string.

Returns:
the position of this address in A1-reference style
Since:
xelem.2.0

getAbsoluteAddress

public String getAbsoluteAddress()
Translates the position of this address into an absolute R1C1-reference string.

Returns:
The position of this address as an absolute R1C1-reference string.

getAbsoluteRange

public String getAbsoluteRange(Address otherAddress)
Gets the absolute range-address of a rectangular range in R1C1-reference style. The rectangle is delimited by this address and otherAddress. This address can be in any of the four corners of the rectangle, as long as otherAddress is in the opposite corner.

Parameters:
otherAddress - The address in the opposite corner.
Returns:
A string in R1C1-reference style.

getAbsoluteRange

public String getAbsoluteRange(int row,
                               int column)
Gets the absolute range-address of a rectangular range in R1C1-reference style. The rectangle is delimited by this address and the cell at the intersection of row and column. This address can be in any of the four corners of the rectangle, as long as the intersection of row and column is in the opposite corner.

Parameters:
row - The row of the cell in the opposite corner.
column - The column of the cell in the opposite corner.
Returns:
A string in R1C1-reference style.

getAbsoluteRange

public static String getAbsoluteRange(Collection<Address> addresses)
Gets the absolute range-address of a collection of addresses in R1C1-reference style.

Parameters:
addresses - A collection of addresses.
Returns:
A string in R1C1-reference style or null if the list is empty.
Throws:
ClassCastException - If the addresses provided are not of equal class.

getRefTo

public String getRefTo(Address otherAddress)
Gets a relative reference from this address to another address in R1C1-reference style.

Parameters:
otherAddress - The referenced address.
Returns:
A string in R1C1-reference style.

getRefTo

public String getRefTo(int row,
                       int column)
Gets a relative reference from this address to a cell at the intersection of row and column in R1C1-reference style.

Parameters:
row - The row to be referenced.
column - The column to be referenced.
Returns:
A string in R1C1-reference style.

getRefTo

public String getRefTo(Address address1,
                       Address address2)
Gets a relative reference from this address to a rectanglular range in R1C1-reference style. The rectangle is delimited by address1 and address2. Address1 can be in any of the four corners of the rectangle, as long as address2 is in the opposite corner.

Parameters:
address1 - The address in one corner of the range to be referenced.
address2 - The address in the opposite corner of the range to be referenced.
Returns:
A string in R1C1-reference style.

getRefTo

public String getRefTo(int r1,
                       int c1,
                       int r2,
                       int c2)
Gets a relative reference from this address to a rectanglular range in R1C1-reference style. The rectangle is delimited by cells at the intersection of r1, c1 and r2, c2 respectively. The intersection of r1, c1 can be in any of the four corners of the rectangle, as long as the intersection of r2, c2 is in the opposite corner.

Parameters:
r1 - The row at intersection 1.
c1 - The column at intersection 1.
r2 - The row at intersection 2.
c2 - The column at intersection 2.
Returns:
A string in R1C1-reference style.

getRefTo

public String getRefTo(Area area)
Gets a relative reference from this address to an area.

Parameters:
area - the area to reference
Returns:
A string in R1C1-reference style.

getRefTo

public String getRefTo(Collection<Address> addresses)
Gets a relative reference from this address to a collection of addresses in R1C1-reference style.

Parameters:
addresses - A collection of addresses.
Returns:
A string in R1C1-reference style or null if the list is empty.
Throws:
ClassCastException - If the addresses provided are not of equal class.

toString

public String toString()
Returns a string representation of this address. Composed as:
          this.getClass().getName() + "[row=x,column=y]"
 
where x and y stand for row- and column index of this address.

Overrides:
toString in class Object
Returns:
A string representation of this address.

equals

public boolean equals(Object obj)
Specifies whether the object in the parameter is equal to this address. Another object is equal to this address if In fact this method invokes the toString-method on both the object and this address and performs the equals-test on these strings.

Overrides:
equals in class Object
Parameters:
obj - An object.
Returns:
true if this address equals obj, false otherwise.

compareTo

public int compareTo(Object o)
Compare this addres with the specified object for order. The specified object is cast to an address. Returns

Specified by:
compareTo in interface Comparable
Parameters:
o - the object to be compared
Returns:
A negative integer, zero, or a positive integer as this address is less then, equal to or greater then the specified object.
Throws:
ClassCastException - If the class of the specified object is not equal to the class of this object.

xelem.3.0