-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBusiness.java
57 lines (49 loc) · 1.94 KB
/
Business.java
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
53
54
55
56
57
package com.doing.more.java.example;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.TreeSet;
public class Business {
protected HashMap<String, EmployeeBean> employees;
protected TreeMap<String, String> customerPhoneBook;
public Business() {
employees = new HashMap<String, EmployeeBean>();
customerPhoneBook = new TreeMap<String, String>();
}
public void addEmployee(EmployeeBean anEmployee) {
if (anEmployee != null && anEmployee.getLastName() != null &&
anEmployee.getFirstName() != null) {
String key = anEmployee.getLastName() +
", " + anEmployee.getFirstName();
employees.put(key, anEmployee);
}
}
public EmployeeBean getEmployee(String lastAndFirstName) {
return employees.get(lastAndFirstName);
}
public String getCustomerPhoneNumber(String lastAndFirstName) {
if(lastAndFirstName == null){
return null;
}
return customerPhoneBook.get(lastAndFirstName);
}
public String getAllCustomerPhoneNumbers() {
StringBuffer phoneNumberBuffer = new StringBuffer();
TreeSet<String> sortedKeys = new TreeSet<String>(customerPhoneBook.keySet());
for(String aKey : sortedKeys){
String phoneNumber = customerPhoneBook.get(aKey);
phoneNumberBuffer.append(aKey);
phoneNumberBuffer.append(" - ");
phoneNumberBuffer.append(phoneNumber);
phoneNumberBuffer.append("; ");
}
return phoneNumberBuffer.toString();
}
public void addCustomerToPhoneBook(CustomerBean aCustomer) {
if (aCustomer != null && aCustomer.getLastName() != null &&
aCustomer.getFirstName() != null) {
String key = aCustomer.getLastName() +
", " + aCustomer.getFirstName();
customerPhoneBook.put(key, aCustomer.getPhoneNumber());
}
}
}