1 2 package org.objectweb.jac.samples.contacts; 3 4 import java.util.Iterator ; 5 import java.util.List ; 6 import java.util.Vector ; 7 8 public class FilteredContacts extends ContactRepository { 9 10 ContactRepository contactRepository = null; 11 CompanyRepository companyRepository = null; 12 13 public FilteredContacts() { 14 } 15 16 public FilteredContacts(ContactRepository repository) { 17 contactRepository = repository; 18 contacts.addAll(contactRepository.getContacts()); 19 } 20 21 public ContactRepository getContactRepository() { 22 return contactRepository; 23 } 24 public void setContactRepository(ContactRepository cr) { 25 this.contactRepository = cr; 26 } 27 28 32 public void addContact(Person contact) { 33 contactRepository.addContact(contact); 34 contacts.add(contact); 35 } 36 37 41 public void removeContact(Person contact) { 42 contactRepository.removeContact(contact); 43 contacts.remove(contact); 44 } 45 46 public void showAll() { 47 search(".*", null); 48 } 49 50 public CompanyRepository companies() { 51 if (companyRepository == null) 52 companyRepository = new CompanyRepository(contactRepository); 53 companyRepository.showAll(); 54 return companyRepository; 55 } 56 57 63 public void search(String criteria, Company company) { 64 contacts.clear(); 65 String name = ""; 66 if (company!=null) { 67 name = company.getName(); 68 } 69 List foundContacts = contactRepository.find(criteria,name); 70 Iterator it = foundContacts.iterator(); 71 while (it.hasNext()) { 72 Person contact = (Person) it.next(); 73 if (!contacts.contains(contact)) 74 contacts.add(contact); 75 } 76 77 105 } 106 107 } 108 | Popular Tags |