1 package org.columba.addressbook.model; 19 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 import org.columba.addressbook.folder.IContactFolder; 24 25 public class ContactModelFactory { 26 27 public static IGroupModelPartial createGroupPartial(IGroupModel group, 28 IContactFolder folder) { 29 if (group == null) 30 throw new IllegalArgumentException ("group == null"); 31 if (folder == null) 32 throw new IllegalArgumentException ("folder == null"); 33 34 IGroupModelPartial groupPartial = new GroupModelPartial(folder.getId(), group 35 .getName(), group.getDescription()); 36 37 String [] members = group.getMembers(); 39 Map <String , IContactModelPartial> map = folder 40 .getContactItemMap(members); 41 42 Iterator <IContactModelPartial> it = map.values().iterator(); 43 while (it.hasNext()) { 44 IContactModelPartial partial = it.next(); 45 46 groupPartial.addContact(partial); 47 } 48 49 return groupPartial; 50 } 51 52 public static IContactModelPartial createContactModelPartial( 53 IContactModel model, String id) { 54 if (model == null) 55 throw new IllegalArgumentException ("model == null"); 56 if (id == null) 57 throw new IllegalArgumentException ("id == null"); 58 59 String sortString = model.getSortString(); 60 61 66 if (sortString == null || sortString.length() == 0) 68 sortString = model.getFormattedName(); 69 70 if (sortString == null || sortString.length() == 0) 72 sortString = model.getPreferredEmail(); 73 74 IContactModelPartial item = new ContactModelPartial(id, sortString, 75 model.getGivenName(), model.getFamilyName(), model 76 .getPreferredEmail(), model.getHomePage()); 77 78 return item; 79 } 80 } 81 | Popular Tags |