1 package org.columba.addressbook.model; 19 20 public class EmailModel implements IEmailModel { 21 22 public static final String [] NAMES = new String [] { "work", "home", "other" }; 23 24 public static final int TYPE_WORK = 0; 25 26 public static final int TYPE_HOME = 1; 27 28 public static final int TYPE_OTHER = 2; 29 30 private String address; 31 32 private int type; 33 34 public EmailModel(String address, int type) { 35 if (address == null) 36 throw new IllegalArgumentException ("address == null"); 37 if (type < 0 || type >=NAMES.length) 38 throw new IllegalArgumentException ("type is not supported= " + type); 39 40 this.address = address; 41 this.type = type; 42 } 43 44 public EmailModel(String address, String type) { 45 if (address == null) 46 throw new IllegalArgumentException ("address == null"); 47 this.address = address; 48 49 boolean foundMatch = false; 50 for (int i = 0; i < NAMES.length; i++) { 51 if (type.equals(NAMES[i])) { 52 foundMatch = true; 53 this.type = i; 54 } 55 } 56 57 if (type.equals("internet")) { 59 foundMatch = true; 60 this.type = 0; 61 } 62 63 64 if( type.equals("x400")) { 66 foundMatch = true; 67 this.type = 0; 68 } 69 70 if (!foundMatch) 71 throw new IllegalArgumentException ("unsupported type: " + type); 72 73 } 74 75 78 public String getAddress() { 79 return address; 80 } 81 82 85 public int getType() { 86 return type; 87 } 88 89 92 public String getTypeString() { 93 return NAMES[type]; 94 } 95 } 96
| Popular Tags
|