1 package addressbook
2
3 class Contact(
4 val name : String,
5 val emails : List<EmailAddress>,
6 val addresses : List<PostalAddress>,
7 val phonenums : List<PhoneNumber>
8 )
9
10 class EmailAddress(
11 val user : String,
12 val host : String
13 )
14
15 class PostalAddress(
16 val streetAddress : String,
17 val city : String,
18 val zip : String,
19 val state : USState?,
20 val country : Country
<lambda>null21 ) {
22 assert {(state == null) xor (country == Countries["US"]) }
23 }
24
25 class PhoneNumber(
26 val country : Country,
27 val areaCode : Int,
28 val number : Long
29 )
30
31 object Countries {
getnull32 fun get(id : CountryID) : Country = countryTable[id]
33
34 private var table : Map<String, Country>? = null
35 private val countryTable : Map<String, Country>
36 get() {
37 if (table == null) {
38 table = HashMap()
39 for (line in TextFile("countries.txt").lines(stripWhiteSpace = true)) {
40 table[line] = Country(line)
41 }
42 }
43 return table
44 }
45 }
46
47 class Country(val name : String)