01: package org.databene.region;
02:
03: import java.util.Collection;
04: import java.util.Map;
05: import java.util.HashMap;
06: import java.util.Locale;
07:
08: /**
09: * Represents a geographical region.
10: * Regions may form a composition structure from continents to multi-country regions, countries, states and so on.<br/>
11: * <br/>
12: * Created: 25.06.2006 22:28:04
13: */
14: public abstract class Region {
15:
16: private static Map<String, Region> instances = new HashMap<String, Region>();
17: private static Region defaultRegion = new BasicRegion(Locale
18: .getDefault().getCountry());
19:
20: static {
21: for (Country country : Country.getInstances())
22: country.getRegion();
23: }
24:
25: public static Region getInstance(String regionCode) {
26: if (regionCode == null)
27: return null;
28: Region instance = instances.get(regionCode);
29: if (instance == null)
30: throw new IllegalArgumentException(
31: "No region of this code defined: " + regionCode);
32: return instance;
33: }
34:
35: public static Region valueOf(String regionCode) {
36: return getInstance(regionCode);
37: }
38:
39: protected String code;
40:
41: public Region(String code) {
42: this .code = code;
43: instances.put(code, this );
44: }
45:
46: public static Region getDefault() {
47: return defaultRegion;
48: }
49:
50: public String getCode() {
51: return code;
52: }
53:
54: public abstract boolean contains(Region region);
55:
56: public abstract Collection countries();
57:
58: }
|