Package com.storedobject.common
Class Address
java.lang.Object
com.storedobject.common.Address
- Direct Known Subclasses:
AEAddress
,CHAddress
,GBAddress
,INAddress
,MYAddress
,PKAddress
,USAddress
,XXAddress
Class to check and manipulate mailing address information. Address is a
First line: CCdX where
CC = the ISO 2 character country code (Example: IN for India, PK for Pakistan, US for USA)
d = Digit 0, 1, 2 or 3 (0 for Apartment, 1 for Villa, 2 for House, 3 for Office)
X = Apartment/villa/office number/name. Can contain any free text but can't be blank
Second line: Building name (may include floor/level etc.). Mandatory for apartments.
Third line: Street name.
Fourth line: Area/Community name.
Depending on the country, rest of the lines are interpreted.
Generic address is formatted as follows:
Line 0: Apartment/Villa/House XXX
Line 1: Building Name
Line 2: Street Name
Line 3: Area/Community Name
Line 4: Country Name
String
containing multiple lines
of text (delimited by newline character). A valid address is stored in the following format:First line: CCdX where
CC = the ISO 2 character country code (Example: IN for India, PK for Pakistan, US for USA)
d = Digit 0, 1, 2 or 3 (0 for Apartment, 1 for Villa, 2 for House, 3 for Office)
X = Apartment/villa/office number/name. Can contain any free text but can't be blank
Second line: Building name (may include floor/level etc.). Mandatory for apartments.
Third line: Street name.
Fourth line: Area/Community name.
Depending on the country, rest of the lines are interpreted.
Generic address is formatted as follows:
Line 0: Apartment/Villa/House XXX
Line 1: Building Name
Line 2: Street Name
Line 3: Area/Community Name
Line 4: Country Name
- Author:
- Syam
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
arrangeLines
(ArrayList<String> lines) This method is invoked for arranging the address lines to be displayed.static String
Check correctness of the format of the given address.static String
Check correctness of the format of the given address.boolean
Copy details from the given address.static Address
Create a blank country specific address.static Address
Create a country specific address from the give details.encode()
Encode the address.Get the apartment/villa/house/office name.Get the caption for the "area" line.Get area name.Get the building name.Get country of this address.int
Get the number of extra lines.Get the apartment/villa/house/office name.getLine
(int lineNumber) Get a line (extra line) from the address.Get the apartment/villa/house/office name.final int
getPOBox()
Get the Post Box number.Get the caption for the Post Box.final String
Get the Postal Code.Get the caption for the Postal Code.int
What is the maximum length of the postal code?int
What is the minimum length of the postal code?Get street name.char
getType()
Get the type code.Get the type code value.static String
getTypeValue
(char type) Get the type code value for the given type.static StringList
Get the type of addresses.Get the apartment/villa/house/office name.boolean
Whether the postal code is numeric or not.final boolean
Check if this is a Post Box based address.final boolean
Check if this is a Postal Code based address.boolean
Is postal code mandatory?final boolean
isValid()
Returns if the address is valid or not.Prefix to be used when printing the PO box.Suffix to be used when printing the PO box.void
setApartmentName
(String apartmentName) Set the apartment/villa/house/office name.void
setAreaName
(String areaName) Set area name.void
setBuildingName
(String buildingName) Set the building name.void
setHouseName
(String houseName) Set the apartment/villa/house/office name.void
Set an address line (extra line).void
setOfficeName
(String officeName) Set the apartment/villa/house/office name.final void
setPOBox
(int poBox) Set the Post Box number.final void
setPostalCode
(String postalCode) Set the Postal Code.void
setStreetName
(String streetName) Set street name.void
setType
(char type) Set the type code.void
setVillaName
(String villaName) Set the apartment/villa/house/office name.final String
toString()
Convert the address into a human-readable String representation.Same astoString()
method but the name passed is included as the first line in the case of personal address or second name in the case of office addresses. .final void
validate()
Validate the address.
-
Method Details
-
check
Check correctness of the format of the given address.- Parameters:
address
- Address- Returns:
- Address (may be modified).
- Throws:
SOException
- If the email format is not valid
-
check
Check correctness of the format of the given address.- Parameters:
address
- AddressallowEmpty
- Whether empty should be taken as valid or not- Returns:
- Address (may be modified).
- Throws:
SOException
- If the email format is not valid
-
isValid
public final boolean isValid()Returns if the address is valid or not.- Returns:
- True or false.
-
validate
-
copy
Copy details from the given address. Country will not be copied.- Parameters:
address
- Address from which details to be copied.- Returns:
- True if the address is valid after copying details.
-
create
-
create
-
toString
-
toString
Same astoString()
method but the name passed is included as the first line in the case of personal address or second name in the case of office addresses. .- Parameters:
personName
- Person name to be included- Returns:
- Human-readable String representation with required "new lines".
-
arrangeLines
-
encode
Encode the address.- Returns:
- Encoded address. Null will be returned if the address is not valid.
-
getExtraLines
public int getExtraLines()Get the number of extra lines.- Returns:
- Number of extra lines in the address.
-
getLine
Get a line (extra line) from the address.- Parameters:
lineNumber
- Line number- Returns:
- Line if exists, else null.
-
setLine
Set an address line (extra line).- Parameters:
lineNumber
- Line number.line
- Value to be set.
-
getTypeValue
-
getTypeValue
Get the type code value for the given type.- Returns:
- Type code value.
-
getTypeValues
-
getType
public char getType()Get the type code.- Returns:
- Type code.
-
setType
public void setType(char type) Set the type code.- Parameters:
type
- Type code
-
getApartmentName
Get the apartment/villa/house/office name.- Returns:
- Apartment/villa/house/office name.
-
setApartmentName
Set the apartment/villa/house/office name.- Parameters:
apartmentName
- Apartment/villa/house/office name
-
getVillaName
Get the apartment/villa/house/office name.- Returns:
- Apartment/villa/house/office name.
-
setVillaName
Set the apartment/villa/house/office name.- Parameters:
villaName
- Apartment/villa/house/office name
-
getHouseName
Get the apartment/villa/house/office name.- Returns:
- Apartment/villa/house/office name.
-
setHouseName
Set the apartment/villa/house/office name.- Parameters:
houseName
- Apartment/villa/house/office name
-
getOfficeName
Get the apartment/villa/house/office name.- Returns:
- Apartment/villa/house/office name.
-
setOfficeName
Set the apartment/villa/house/office name.- Parameters:
officeName
- Apartment/villa/house/office name
-
getBuildingName
-
setBuildingName
Set the building name.- Parameters:
buildingName
- Building name to be set
-
getStreetName
-
setStreetName
Set street name.- Parameters:
streetName
- Street name to set
-
getAreaName
-
setAreaName
-
getCountry
-
isPOBoxAddress
public final boolean isPOBoxAddress()Check if this is a Post Box based address.- Returns:
- True or false.
-
setPOBox
public final void setPOBox(int poBox) Set the Post Box number.- Parameters:
poBox
- Post Box number
-
getPOBox
public final int getPOBox()Get the Post Box number.- Returns:
- Post Box number.
-
poBoxPrefix
Prefix to be used when printing the PO box.- Returns:
- By default,
getPOBoxName()
is returned.
-
poBoxSuffix
Suffix to be used when printing the PO box.- Returns:
- By default, an empty string is returned.
-
isPostalCodeAddress
public final boolean isPostalCodeAddress()Check if this is a Postal Code based address.- Returns:
- True or false.
-
getPostalCode
-
setPostalCode
Set the Postal Code.- Parameters:
postalCode
- Postal Code
-
getPostalCodeCaption
Get the caption for the Postal Code.- Returns:
- Default implementation returns "Postal Code".
-
isNumericPostalCode
public boolean isNumericPostalCode()Whether the postal code is numeric or not.- Returns:
- True if numeric. False if alpha-numeric.
-
isPostalCodeMandatory
public boolean isPostalCodeMandatory()Is postal code mandatory?- Returns:
- True/false.
-
getPostalCodeMinLength
public int getPostalCodeMinLength()What is the minimum length of the postal code?- Returns:
- Minimum required length of the postal code.
-
getPostalCodeMaxLength
public int getPostalCodeMaxLength()What is the maximum length of the postal code?- Returns:
- Maximum required length of the postal code.
-
getPOBoxName
Get the caption for the Post Box.- Returns:
- Default implementation returns "Post Box".
-
getAreaCaption
Get the caption for the "area" line.- Returns:
- Default implementation returns "Area".
-