postalcode
Class PostalCode

java.lang.Object
  |
  +--postalcode.PostalCode
Direct Known Subclasses:
BritishPostalCode, CanadianPostalCode, USZipCode

public abstract class PostalCode
extends java.lang.Object

This class is the superclass which defines the basics of any postal code. Some methods are abstract and must be overriden.


Field Summary
private  java.lang.String code
          The postal code to be analysed.
private  java.lang.String destination
          The destination location of the postal code.
private  boolean hasBeenValidated
          Whether the code has been validated.
private  boolean isValid
          Once validated, whether the code is valid or not.
 
Constructor Summary
PostalCode(java.lang.String code)
          Constructs a postal code object using information passed by the subclass constructors.
 
Method Summary
 java.lang.String getCode()
          Retrieves the postal code.
abstract  java.lang.String getCountry()
          This method returns the country of origin of the postal code.
 java.lang.String getDestination()
          Retrieves the postal code's destination.
 boolean isValid()
          Verifies if the postal is valid.
 void setDestination(java.lang.String destination)
          Sets the postal code's destination.
(package private)  void throwException(java.lang.String message)
          This method will cause an exception to be thrown.
 java.lang.String toString()
          General information about this object.
protected abstract  void validate()
          This method is used to verify the validity of a postal code.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

code

private java.lang.String code
The postal code to be analysed.

hasBeenValidated

private boolean hasBeenValidated
Whether the code has been validated.

isValid

private boolean isValid
Once validated, whether the code is valid or not.

destination

private java.lang.String destination
The destination location of the postal code.
Constructor Detail

PostalCode

public PostalCode(java.lang.String code)
           throws PostalCodeException
Constructs a postal code object using information passed by the subclass constructors.
Parameters:
code - The postal code to be analysed.
Method Detail

toString

public java.lang.String toString()
General information about this object.
Returns:
A string representation of a postal code object.
Overrides:
toString in class java.lang.Object

getCode

public java.lang.String getCode()
Retrieves the postal code.
Returns:
A String containing the postal code.

getDestination

public java.lang.String getDestination()
Retrieves the postal code's destination.
Returns:
A String containing the postal code's destination.

setDestination

public void setDestination(java.lang.String destination)
Sets the postal code's destination.
Parameters:
destination - The postal code's destination.

isValid

public boolean isValid()
                throws PostalCodeException
Verifies if the postal is valid. If it has not been validated, it calls the validation method.
Returns:
TRUE if the code is valid, FALSE if it is not.
Throws:
PostalCodeException - If the code is found to be invalid during the call to the validation method.

throwException

void throwException(java.lang.String message)
              throws PostalCodeException
This method will cause an exception to be thrown. Called when a postal code is found to be invalid.
Parameters:
message - The detailed message about the cause of the exception.
Throws:
PostalCodeException - If the code is found to be invalid.

validate

protected abstract void validate()
                          throws PostalCodeException
This method is used to verify the validity of a postal code.
Throws:
PostalCodeException - If the code is found to be invalid.

getCountry

public abstract java.lang.String getCountry()
This method returns the country of origin of the postal code.
Returns:
A String containing the country of origin of the code.