001: package org.databene.region;
002:
003: import java.util.*;
004:
005: /**
006: * Represents a city.<br/>
007: * <br/>
008: * Created: 11.06.2006 08:19:23
009: */
010: public class City {
011:
012: // Ort;Zusatz;Plz;Vorwahl;Bundesland
013: private String name;
014: private String nameExtension;
015: private SortedSet<String> zipCodes;
016: private String phoneCode;
017: private State state;
018: private int inhabitants;
019: private Locale language;
020:
021: public City(State state, String name, String addition,
022: Collection<String> zipCodes, String phoneCode) {
023: if (phoneCode == null)
024: throw new IllegalArgumentException(
025: "Phone Code is null for " + name);
026: this .state = state;
027: this .name = name;
028: this .nameExtension = addition;
029: this .zipCodes = new TreeSet<String>(zipCodes);
030: this .phoneCode = phoneCode;
031: }
032:
033: public String getNameExtension() {
034: return nameExtension;
035: }
036:
037: public void setNameExtension(String nameExtension) {
038: this .nameExtension = nameExtension;
039: }
040:
041: public Collection<String> getZipCodes() {
042: return zipCodes;
043: }
044:
045: public void setZipCodes(Collection<String> zipCodes) {
046: this .zipCodes.clear();
047: this .zipCodes.addAll(zipCodes);
048: }
049:
050: public void addZipCode(String zipCode) {
051: zipCodes.add(zipCode);
052: }
053:
054: public String getPhoneCode() {
055: return phoneCode;
056: }
057:
058: public void setPhoneCode(String phoneCode) {
059: this .phoneCode = phoneCode;
060: }
061:
062: public State getState() {
063: return state;
064: }
065:
066: public void setState(State state) {
067: this .state = state;
068: }
069:
070: public String getName() {
071: return name;
072: }
073:
074: public Locale getLanguage() {
075: return language;
076: }
077:
078: public void setLanguage(Locale language) {
079: this .language = language;
080: }
081:
082: public int getInhabitants() {
083: return inhabitants;
084: }
085:
086: public void setInhabitants(int inhabitants) {
087: this .inhabitants = inhabitants;
088: }
089:
090: // java.lang.Object overrides --------------------------------------------------------------------------------------
091:
092: public String toString() {
093: return name
094: + (nameExtension.length() > 0
095: && Character.isLetter(nameExtension.charAt(0)) ? " "
096: : "") + nameExtension;
097: }
098:
099: public boolean equals(Object o) {
100: if (this == o)
101: return true;
102: if (o == null || getClass() != o.getClass())
103: return false;
104:
105: final City city = (City) o;
106: if (nameExtension != null ? !nameExtension
107: .equals(city.nameExtension)
108: : city.nameExtension != null)
109: return false;
110: return name.equals(city.name);
111:
112: }
113:
114: public int hashCode() {
115: int result;
116: result = name.hashCode();
117: result = 29
118: * result
119: + (nameExtension != null ? nameExtension.hashCode() : 0);
120: return result;
121: }
122:
123: }
|