Holger's
Java API

com.antelmann.crm
Class SnailMailAddress

java.lang.Object
  extended by com.antelmann.crm.SnailMailAddress
All Implemented Interfaces:
XMLSerializable, DetailedString, Forgeable<SnailMailAddress>, Localizable, Serializable
Direct Known Subclasses:
ImmutableSnailMailAddress

public class SnailMailAddress
extends Object
implements Serializable, Forgeable<SnailMailAddress>, DetailedString, Localizable, XMLSerializable

represents a structured local address

Since:
5. Juli 2007, 11:39
Author:
Holger Antelmann
See Also:
ImmutableSnailMailAddress, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.antelmann.util.Localizable
Localizable.Adapter
 
Field Summary
static DataFlavor ADDRESS_FLAVOR
           
 
Constructor Summary
SnailMailAddress()
           
SnailMailAddress(SnailMailAddress adr)
           
SnailMailAddress(String fullAddress)
          the given String is used as the overriding fullAddress for the default locale
 
Method Summary
 void clearAll()
          allows to clear all fields of this address
 boolean equals(Object obj)
           
 void exportXML(OutputStream out)
          exports the entire object as XML and writes it to the given Writer, so that the object can be reconstructed with importXML(InputSource).
 String getAddressString()
          returns the address string to be used for the current locale
 String getAddressString(Locale l)
          returns the address for use in a document.
 String getCity()
           
 String getCountry()
          returns the ISO 3166 2-letter code
 String getCountryName()
           
 String getCountryName(Locale l)
           
 String getFormattedAddress()
          calls getFormattedAddress(Locale) with the current locale
 String getFormattedAddress(Locale l)
          constructs the address based on certain standards; a plain '\n' is used for line breaks.
 String getFullAddress()
          calls getFullAddress([current locale])
 String getFullAddress(Locale l)
          a non-null return value is used to override how the address is constructed
 Map<Locale,String> getFullAddressMap()
          returns an unmodifiable view of the embedded full address map
 Locale getLocale()
          allows access to the Locale that this instance currently uses to localize its messages,
 String getState()
           
 String getStreet()
          may contain multiple lines
 String getStreetNumber()
           
 String getTitle()
          may contain multiple lines
 String getZip()
           
 int hashCode()
           
 void importXML(InputStream source)
          The object is fully reinitialized with the XML data contained in the given ImputSource, so that the object has the same state as it had during export.
 boolean isEmpty()
          returns true only if all fields are null
 void replaceEmptyStringsWithNull()
           
 boolean requiresState()
           
static boolean requiresState(String countryCode)
           
 boolean sameAs(SnailMailAddress adr)
           
 void setAllFrom(SnailMailAddress adr)
          copies the properties of the given object and applies them to this instance, so that its behavior in regards to the given object can be matched to the extend that the implementing class supports that behavior.
 void setCity(String city)
           
 void setCountry(String country)
          uses the ISO 3166 2-letter code
 String setFullAddress(String fullAddress)
          sets the address for the current Locale
 String setFullAddress(String fullAddress, Locale l)
          a non-null parameter is used to override how the address is constructed
 void setFullAddressMap(Map<Locale,String> map)
           
 void setLocale(Locale locale)
           
 void setLocale(Locale locale, Object context)
          sets the Locale for this object so that all subsequent return values of method calls to this instance can be localized accordingly until a different Locale is set.
 void setState(String state)
           
 void setStreet(String street)
          may contain multiple lines
 void setStreetNumber(String sn)
           
 void setTitle(String title)
          may contain multiple lines
 void setZip(String zip)
           
 String toDetailedString()
          provides full details of this instance in a String.
 String toString()
          returns the address title in a single line if available
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ADDRESS_FLAVOR

public static final DataFlavor ADDRESS_FLAVOR
Constructor Detail

SnailMailAddress

public SnailMailAddress()

SnailMailAddress

public SnailMailAddress(String fullAddress)
the given String is used as the overriding fullAddress for the default locale


SnailMailAddress

public SnailMailAddress(SnailMailAddress adr)
Method Detail

getLocale

public Locale getLocale()
Description copied from interface: Localizable
allows access to the Locale that this instance currently uses to localize its messages,

Specified by:
getLocale in interface Localizable
Returns:
the current Locale that this instance uses to determine return values for its methods; if null is returned, this instance is expected to use the default Locale of the system.
See Also:
Localizable.setLocale(Locale, Object)

setLocale

public void setLocale(Locale locale,
                      Object context)
Description copied from interface: Localizable
sets the Locale for this object so that all subsequent return values of method calls to this instance can be localized accordingly until a different Locale is set.

Specified by:
setLocale in interface Localizable
Parameters:
locale - the Locale that is to be used to determine return values for all methods of this instance; if set to null, the default locale is to be used.
context - a context that may be required for this instance to load the resources for the given locale; this context may be null for objects that do not require an external context. Examples of a context may be a database, a resource file, some map or no context at all.
See Also:
Localizable.getLocale()

setLocale

public void setLocale(Locale locale)

exportXML

public void exportXML(OutputStream out)
               throws IOException
Description copied from interface: XMLSerializable
exports the entire object as XML and writes it to the given Writer, so that the object can be reconstructed with importXML(InputSource). The given stream is neither flushed nor closed, so that other data may be effectively written to the InputSource after the method returned.

Specified by:
exportXML in interface XMLSerializable
Throws:
IOException
See Also:
XMLSerializable.importXML(InputStream)

importXML

public void importXML(InputStream source)
               throws SAXException,
                      IOException
Description copied from interface: XMLSerializable
The object is fully reinitialized with the XML data contained in the given ImputSource, so that the object has the same state as it had during export.

Specified by:
importXML in interface XMLSerializable
Throws:
SAXException
IOException
See Also:
XMLSerializable.exportXML(OutputStream)

clearAll

public void clearAll()
allows to clear all fields of this address


isEmpty

public boolean isEmpty()
returns true only if all fields are null


setAllFrom

public void setAllFrom(SnailMailAddress adr)
                throws NullPointerException
Description copied from interface: Forgeable
copies the properties of the given object and applies them to this instance, so that its behavior in regards to the given object can be matched to the extend that the implementing class supports that behavior.

Specified by:
setAllFrom in interface Forgeable<SnailMailAddress>
Parameters:
adr - the object whose behavior is to be copied to this instance
Throws:
NullPointerException - if the given object parameter is null

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

sameAs

public boolean sameAs(SnailMailAddress adr)

toString

public String toString()
returns the address title in a single line if available

Overrides:
toString in class Object
See Also:
getAddressString()

toDetailedString

public String toDetailedString()
Description copied from interface: DetailedString
provides full details of this instance in a String. In case the String contains multiple lines, it is recommended to use '\n' rather than the platform specific line-break for better compatibility.

Specified by:
toDetailedString in interface DetailedString
Returns:
a (potentially multi-line) String providing full details on this object instance

getAddressString

@Localized
public String getAddressString()
returns the address string to be used for the current locale


getAddressString

public String getAddressString(Locale l)
returns the address for use in a document. If no fullAddress String is set for the given Locale, the formatted address is returned.

See Also:
getFullAddress(Locale), getFormattedAddress(Locale)

getFullAddress

public String getFullAddress()
calls getFullAddress([current locale])


getFullAddress

public String getFullAddress(Locale l)
a non-null return value is used to override how the address is constructed


setFullAddress

public String setFullAddress(String fullAddress)
sets the address for the current Locale


setFullAddress

public String setFullAddress(String fullAddress,
                             Locale l)
a non-null parameter is used to override how the address is constructed

Returns:
the fullAddress previously set for the given Locale
See Also:
getAddressString(Locale)

getFullAddressMap

public Map<Locale,String> getFullAddressMap()
returns an unmodifiable view of the embedded full address map


setFullAddressMap

public void setFullAddressMap(Map<Locale,String> map)

getFormattedAddress

public String getFormattedAddress()
calls getFormattedAddress(Locale) with the current locale

See Also:
getFormattedAddress(Locale)

getFormattedAddress

public String getFormattedAddress(Locale l)
constructs the address based on certain standards; a plain '\n' is used for line breaks.


requiresState

public boolean requiresState()

requiresState

public static boolean requiresState(String countryCode)

getTitle

public String getTitle()
may contain multiple lines


setTitle

public void setTitle(String title)
may contain multiple lines


getStreet

public String getStreet()
may contain multiple lines


setStreet

public void setStreet(String street)
may contain multiple lines


getStreetNumber

public String getStreetNumber()

setStreetNumber

public void setStreetNumber(String sn)

getCity

public String getCity()

setCity

public void setCity(String city)

getZip

public String getZip()

setZip

public void setZip(String zip)

getCountry

public final String getCountry()
returns the ISO 3166 2-letter code


getCountryName

public String getCountryName()

getCountryName

public String getCountryName(Locale l)

setCountry

public void setCountry(String country)
                throws IllegalArgumentException
uses the ISO 3166 2-letter code

Throws:
IllegalArgumentException

getState

public String getState()

setState

public void setState(String state)

replaceEmptyStringsWithNull

public void replaceEmptyStringsWithNull()


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads