public class Address extends VCardProperty implements HasAltId
Defines a mailing address.
Code sample (creating)
VCard vcard = new VCard(); Address adr = new Address(); adr.setStreetAddress("123 Main St."); adr.setLocality("Austin"); adr.setRegion("TX"); adr.setPostalCode("12345"); adr.setCountry("USA"); adr.getTypes().add(AddressType.WORK); //optionally, set the text to print on the mailing label adr.setLabel("123 Main St.\nAustin, TX 12345\nUSA"); vcard.addAddress(adr);
Code sample (retrieving)
VCard vcard = ... for (Address adr : vcard.getAddresses()) { String street = adr.getStreetAddress(); String city = adr.getLocality(); //etc. }
Only part of the street address is being returned!
This usually means that the vCard you parsed contains unescaped comma
characters. To get the full address, use the getStreetAddressFull()
method.
Property name: ADR
Supported versions: 2.1, 3.0, 4.0
group, parameters
Constructor and Description |
---|
Address() |
Address(Address original)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_validate(List<ValidationWarning> warnings,
VCardVersion version,
VCard vcard)
Checks the property for data consistency problems or deviations from the
spec.
|
Address |
copy()
Creates a copy of this property object.
|
boolean |
equals(Object obj) |
String |
getAltId()
Gets the property's ALTID parameter.
|
List<String> |
getCountries()
Gets the list that holds the countries that are assigned to this address.
|
String |
getCountry()
Gets the country.
|
String |
getExtendedAddress()
Gets the extended address.
|
List<String> |
getExtendedAddresses()
Gets the list that holds the extended addresses that are assigned to this
address.
|
String |
getExtendedAddressFull()
Gets the extended address.
|
GeoUri |
getGeo()
Gets the global positioning coordinates that are associated with this
address.
|
String |
getLabel()
Gets the label of the address.
|
String |
getLanguage()
Gets the language that the property value is written in.
|
List<String> |
getLocalities()
Gets the list that holds the localities that are assigned to this
address.
|
String |
getLocality()
Gets the locality (city)
|
List<Pid> |
getPids()
Gets the list that stores this property's PID (property ID) parameter
values.
|
String |
getPoBox()
Gets the P.O.
|
List<String> |
getPoBoxes()
Gets the list that holds the P.O.
|
String |
getPostalCode()
Gets the postal code (zip code).
|
List<String> |
getPostalCodes()
Gets the list that holds the postal codes that are assigned to this
address.
|
Integer |
getPref()
Gets this property's preference value.
|
String |
getRegion()
Gets the region (state).
|
List<String> |
getRegions()
Gets the list that holds the regions that are assigned to this address.
|
String |
getStreetAddress()
Gets the street address
|
List<String> |
getStreetAddresses()
Gets the list that holds the street addresses that are assigned to this
address.
|
String |
getStreetAddressFull()
Gets the street address.
|
String |
getTimezone()
Gets the timezone that's associated with this address.
|
List<AddressType> |
getTypes()
Gets the list that stores this property's address types (TYPE
parameters).
|
int |
hashCode() |
void |
setAltId(String altId)
Sets the property's ALTID parameter.
|
void |
setCountry(String country)
Sets the country.
|
void |
setExtendedAddress(String extendedAddress)
Sets the extended address.
|
void |
setGeo(GeoUri uri)
Sets the global positioning coordinates that are associated with this
address.
|
void |
setLabel(String label)
Sets the label of the address.
|
void |
setLanguage(String language)
Sets the language that the property value is written in.
|
void |
setLocality(String locality)
Sets the locality (city).
|
void |
setPoBox(String poBox)
Sets the P.O.
|
void |
setPostalCode(String postalCode)
Sets the postal code (zip code).
|
void |
setPref(Integer pref)
Sets this property's preference value.
|
void |
setRegion(String region)
Sets the region (state).
|
void |
setStreetAddress(String streetAddress)
Sets the street address.
|
void |
setTimezone(String timezone)
Sets the timezone that's associated with this address.
|
protected Map<String,Object> |
toStringValues()
Gets string representations of the class's fields for the
VCardProperty.toString() method. |
addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, isSupportedBy, removeParameter, setGroup, setParameter, setParameters, toString, validate
public Address()
public String getPoBox()
public List<String> getPoBoxes()
public void setPoBox(String poBox)
poBox
- the P.O. box or null to removepublic String getExtendedAddress()
public List<String> getExtendedAddresses()
public String getExtendedAddressFull()
public void setExtendedAddress(String extendedAddress)
extendedAddress
- the extended address (e.g. "Suite 200") or null to
removepublic String getStreetAddress()
public List<String> getStreetAddresses()
public String getStreetAddressFull()
public void setStreetAddress(String streetAddress)
streetAddress
- the street address (e.g. "123 Main St") or null to
removepublic String getLocality()
public List<String> getLocalities()
public void setLocality(String locality)
locality
- the locality or null to removepublic String getRegion()
public List<String> getRegions()
public void setRegion(String region)
region
- the region (e.g. "Texas") or null to removepublic String getPostalCode()
public List<String> getPostalCodes()
public void setPostalCode(String postalCode)
postalCode
- the postal code (e.g. "90210") or null to removepublic String getCountry()
public List<String> getCountries()
public void setCountry(String country)
country
- the country (e.g. "USA") or null to removepublic List<AddressType> getTypes()
public String getLanguage()
VCardProperty
public void setLanguage(String language)
VCardProperty
language
- the language or null to removepublic String getLabel()
public void setLabel(String label)
label
- the label or null to removepublic GeoUri getGeo()
Gets the global positioning coordinates that are associated with this address.
Supported versions: 4.0
VCardParameters.getGeo()
public void setGeo(GeoUri uri)
Sets the global positioning coordinates that are associated with this address.
Supported versions: 4.0
uri
- the geo URI or null to removeVCardParameters.setGeo(ezvcard.util.GeoUri)
public List<Pid> getPids()
VCardProperty
Gets the list that stores this property's PID (property ID) parameter values.
PIDs can exist on any property where multiple instances are allowed (such
as Email
or Address
, but not StructuredName
because only 1 instance of this property is allowed per vCard).
When used in conjunction with the ClientPidMap
property, it
allows an individual property instance to be uniquely identifiable. This
feature is made use of when two different versions of the same vCard have
to be merged together (called "synchronizing").
Supported versions: 4.0
public Integer getPref()
VCardProperty
Gets this property's preference value. The lower this number is, the more "preferred" the property instance is compared with other properties of the same type. If a property doesn't have a preference value, then it is considered the least preferred.
In the vCard below, the Address
on the second row is the most
preferred because it has the lowest PREF value.
ADR;TYPE=work;PREF=2:;;1600 Amphitheatre Parkway;Mountain View;CA;94043 ADR;TYPE=work;PREF=1:;;One Microsoft Way;Redmond;WA;98052 ADR;TYPE=home:;;123 Maple St;Hometown;KS;12345
Supported versions: 4.0
public void setPref(Integer pref)
VCardProperty
Sets this property's preference value. The lower this number is, the more "preferred" the property instance is compared with other properties of the same type. If a property doesn't have a preference value, then it is considered the least preferred.
In the vCard below, the Address
on the second row is the most
preferred because it has the lowest PREF value.
ADR;TYPE=work;PREF=2:;;1600 Amphitheatre Parkway;Mountain View;CA;94043 ADR;TYPE=work;PREF=1:;;One Microsoft Way;Redmond;WA;98052 ADR;TYPE=home:;;123 Maple St;Hometown;KS;12345
Supported versions: 4.0
pref
- the preference value or null to removepublic String getAltId()
HasAltId
Supported versions: 4.0
getAltId
in interface HasAltId
VCardParameters.getAltId()
public void setAltId(String altId)
HasAltId
Supported versions: 4.0
setAltId
in interface HasAltId
altId
- the ALTID or null to removeVCardParameters.setAltId(java.lang.String)
public String getTimezone()
Supported versions: 4.0
public void setTimezone(String timezone)
Supported versions: 4.0
timezone
- the timezone (e.g. "America/New_York") or null to removeprotected void _validate(List<ValidationWarning> warnings, VCardVersion version, VCard vcard)
VCardProperty
_validate
in class VCardProperty
warnings
- the list to add the warnings toversion
- the version to check the property againstvcard
- the vCard this property belongs toprotected Map<String,Object> toStringValues()
VCardProperty
Gets string representations of the class's fields for the
VCardProperty.toString()
method.
Meant to be overridden by child classes. The default implementation returns an empty map.
toStringValues
in class VCardProperty
public Address copy()
VCardProperty
Creates a copy of this property object.
The default implementation of this method uses reflection to look for a copy constructor. Child classes SHOULD override this method to avoid the performance overhead involved in using reflection.
The child class's copy constructor, if present, MUST invoke the
VCardProperty.VCardProperty(VCardProperty)
super constructor to ensure that
the group name and parameters are also copied.
This method MUST be overridden by the child class if the child class does
not have a copy constructor. Otherwise, an
UnsupportedOperationException
will be thrown when an attempt is
made to copy the property (such as in the VCard
class's copy constructor
).
copy
in class VCardProperty
public int hashCode()
hashCode
in class VCardProperty
public boolean equals(Object obj)
equals
in class VCardProperty
Copyright © 2012–2023 Michael Angstadt. All rights reserved.