在java中表示西班牙地址的最佳方式
我已对以下内容进行编码以代表西班牙的地址。如果有更好的方法可以做到这一点,或者是否已经有一个处理 i18n 地址的开源库,请告诉我。
/**
* From <a href="http://www.addressdoctor.com/en/countries_data/sampleaddress.asp?code=ESP%2BSpain}">Address doctor</a>
* <p>
* Format
* </p>
*
* <pre>
* Line 1: RECIPIENT
* Line 2: [URBANISATION]
* Line 3: STREET_TYPE STREET_NAME, HOUSE_NUMBER [FLOOR] [APARTMENT]
* Line 4: POSTAL_CODE LOCALITY
* Line 5: SPAIN
* </pre>
*
* Example
*
* <pre>
* Isidre Varo
* Avenida de Canillejas a Vicalvaro 82 piso 4
* 28022 MADRID
* SPAIN
* </pre>
*
* @author Aravind R Yarram
*
*/
public interface SpainAddress
{
/**
* E.g road types would be Calle (Street)
* <p>
* TODO may be an enumeration
* </p>
*/
String getStreetType();
String getStreetName();
String getHouseNumber();
String getFloorNumber();
/**
* <p>
* TODO need validation
* </p>
*/
String getPostalCode();
/**
* Poblacion
*/
String getCity();
/**
* Also known as province
*/
String getLocality();
}
I have coded the below to represent addresses in Spain. Let me know if there are better ways of doing this or if there is already a open source library dealing with i18n addresses.
/**
* From <a href="http://www.addressdoctor.com/en/countries_data/sampleaddress.asp?code=ESP%2BSpain}">Address doctor</a>
* <p>
* Format
* </p>
*
* <pre>
* Line 1: RECIPIENT
* Line 2: [URBANISATION]
* Line 3: STREET_TYPE STREET_NAME, HOUSE_NUMBER [FLOOR] [APARTMENT]
* Line 4: POSTAL_CODE LOCALITY
* Line 5: SPAIN
* </pre>
*
* Example
*
* <pre>
* Isidre Varo
* Avenida de Canillejas a Vicalvaro 82 piso 4
* 28022 MADRID
* SPAIN
* </pre>
*
* @author Aravind R Yarram
*
*/
public interface SpainAddress
{
/**
* E.g road types would be Calle (Street)
* <p>
* TODO may be an enumeration
* </p>
*/
String getStreetType();
String getStreetName();
String getHouseNumber();
String getFloorNumber();
/**
* <p>
* TODO need validation
* </p>
*/
String getPostalCode();
/**
* Poblacion
*/
String getCity();
/**
* Also known as province
*/
String getLocality();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我住在马德里并且能说流利的西班牙语,我可以提供一些评论。
我不会将街道类型和名称分开,因为街道类型通常是名称的一部分,或者可能会丢失(例如 Gran Via)。任何解析算法要么会出现一些错误,要么需要大量的异常表(并且仍然会出现一些错误)。
在地方之后为省提供一个字段。这是具有欺骗性的,因为对于大城市来说,省份经常被省略,特别是在城市名称和省份名称相同的情况下。以下是地区和省份不同的示例:
Having lived in Madrid and being fluent in Spanish, I can offer a couple of comments.
I wouldn't separate street type and name, because the street type is often really part of the name, or may be missing (Gran Via, for instance). Any parsing algorithm will either get some wrong or require a huge table of exceptions (and it'll still get some wrong).
Provide a field for the Province, after the Locality. This is deceptive because for large cities the province is often omitted, especially where the city name and province name are the same. Here's an example where the locality and province are different: