-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactManager.java
More file actions
52 lines (39 loc) · 1.53 KB
/
ContactManager.java
File metadata and controls
52 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.List;
public class ContactManager {
private ContactRepository repository;
public ContactManager() {
repository = new ContactRepository();
}
public String createContact(String name, String phone, String email, String address)
throws ValidationException {
ContactValidator.validateContact(name, phone, email);
String id = repository.generateId();
Contact contact = new Contact(id, name, phone, email, address);
repository.addContact(contact);
return id;
}
public Contact getContact(String id) {
return repository.getContact(id);
}
public List<Contact> getAllContacts() {
return repository.getAllContacts();
}
public boolean updateContact(String id, String name, String phone,
String email, String address) throws ValidationException {
ContactValidator.validateContact(name, phone, email);
Contact contact = new Contact(id, name, phone, email, address);
return repository.updateContact(id, contact);
}
public boolean deleteContact(String id) {
return repository.deleteContact(id);
}
public List<Contact> searchByName(String name) {
return repository.searchByName(name);
}
public List<Contact> searchByPhone(String phone) {
return repository.searchByPhone(phone);
}
public int getContactCount() {
return repository.getAllContacts().size();
}
}