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 voidarrangeLines(ArrayList<String> lines) This method is invoked for arranging the address lines to be displayed.static StringCheck correctness of the format of the given address.static StringCheck correctness of the format of the given address.booleanCopy details from the given address.static AddressCreate a blank country specific address.static AddressCreate 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.intGet 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 intgetPOBox()Get the Post Box number.Get the caption for the Post Box.final StringGet the Postal Code.Get the caption for the Postal Code.intWhat is the maximum length of the postal code?intWhat is the minimum length of the postal code?Get street name.chargetType()Get the type code.Get the type code value.static StringgetTypeValue(char type) Get the type code value for the given type.static StringListGet the type of addresses.Get the apartment/villa/house/office name.booleanWhether the postal code is numeric or not.final booleanCheck if this is a Post Box based address.final booleanCheck if this is a Postal Code based address.booleanIs postal code mandatory?final booleanisValid()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.voidsetApartmentName(String apartmentName) Set the apartment/villa/house/office name.voidsetAreaName(String areaName) Set area name.voidsetBuildingName(String buildingName) Set the building name.voidsetHouseName(String houseName) Set the apartment/villa/house/office name.voidSet an address line (extra line).voidsetOfficeName(String officeName) Set the apartment/villa/house/office name.final voidsetPOBox(int poBox) Set the Post Box number.final voidsetPostalCode(String postalCode) Set the Postal Code.voidsetStreetName(String streetName) Set street name.voidsetType(char type) Set the type code.voidsetVillaName(String villaName) Set the apartment/villa/house/office name.final StringtoString()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 voidvalidate()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".
-