|
@@ -3,72 +3,77 @@ package com.zipcodewilmington.phonebook;
|
3
|
3
|
import java.util.TreeMap;
|
4
|
4
|
import java.util.Set;
|
5
|
5
|
import java.util.ArrayList;
|
|
6
|
+
|
6
|
7
|
/**
|
7
|
8
|
* Created by leon on 1/23/18.
|
8
|
9
|
*/
|
9
|
10
|
public class PhoneBook {
|
10
|
11
|
|
11
|
|
- String name;
|
12
|
|
- String phonenum;
|
13
|
|
- //TreeMap<String, String> contacts = new TreeMap<String, String>();
|
|
12
|
+ String name;
|
|
13
|
+ String phonenum;
|
|
14
|
+ //TreeMap<String, String> contacts = new TreeMap<String, String>();
|
14
|
15
|
// TreeMap<String, ArrayList> contacts = new TreeMap<String, ArrayList<String>>();
|
15
|
16
|
TreeMap<String, PhoneNumberStorage> contacts = new TreeMap<String, PhoneNumberStorage>();
|
16
|
17
|
|
17
|
18
|
|
|
19
|
+ public PhoneBook() {
|
|
20
|
+ }
|
18
|
21
|
|
19
|
|
-public PhoneBook() {
|
20
|
|
-}
|
21
|
|
-
|
22
|
|
- public void addName(String name, String phonenum){
|
23
|
|
- contacts.put(name, new PhoneNumberStorage(name, phonenum));
|
24
|
|
- }
|
|
22
|
+ public void addName(String name, String phonenum) {
|
|
23
|
+ contacts.put(name, new PhoneNumberStorage(name, phonenum));
|
|
24
|
+ }
|
25
|
25
|
|
26
|
|
- public void addName(String name, PhoneNumberStorage phoneNumberStorage){
|
|
26
|
+ public void addName(String name, PhoneNumberStorage phoneNumberStorage) {
|
27
|
27
|
contacts.put(name, phoneNumberStorage);
|
28
|
28
|
}
|
29
|
29
|
|
30
|
|
- public void deleter(String name){
|
|
30
|
+ public void deleter(String name) {
|
31
|
31
|
contacts.remove(name);
|
32
|
|
- }
|
|
32
|
+ }
|
33
|
33
|
|
34
|
|
- public PhoneNumberStorage lookup(String name){
|
|
34
|
+ public PhoneNumberStorage lookup(String name) {
|
35
|
35
|
return contacts.get(name);
|
36
|
|
- }
|
|
36
|
+ }
|
37
|
37
|
|
38
|
|
- public String listNames(){
|
39
|
|
- StringBuilder namesnumbers = new StringBuilder();
|
|
38
|
+ public String listNames() {
|
|
39
|
+ StringBuilder namesnumbers = new StringBuilder();
|
40
|
40
|
Set<String> keys = contacts.keySet();
|
41
|
|
- for(String key: keys)
|
|
41
|
+ for (String key : keys)
|
42
|
42
|
|
43
|
43
|
{
|
44
|
44
|
|
45
|
|
- namesnumbers.append(key+"\n");
|
|
45
|
+ namesnumbers.append(key + "\n");
|
46
|
46
|
}
|
47
|
47
|
return namesnumbers.toString();
|
48
|
|
- }
|
|
48
|
+ }
|
49
|
49
|
|
50
|
|
- public String listNamesAndNumbers(){
|
|
50
|
+ public String listNamesAndNumbers() {
|
51
|
51
|
StringBuilder namesnumbers = new StringBuilder();
|
52
|
52
|
Set<String> keys = contacts.keySet();
|
53
|
|
- for(String key: keys)
|
54
|
|
- {
|
55
|
|
- namesnumbers.append(key+" "+contacts.get(key)+"\n");
|
|
53
|
+ for (String key : keys) {
|
|
54
|
+ namesnumbers.append(key + " " + contacts.get(key) + "\n");
|
56
|
55
|
}
|
57
|
56
|
return namesnumbers.toString();
|
58
|
57
|
}
|
59
|
58
|
|
60
|
|
- public String reverselookup(String number){
|
|
59
|
+ public String reverselookup(String number) {
|
61
|
60
|
//Set<String> names = contacts.keySet();
|
62
|
|
- for(PhoneNumberStorage nums : contacts.values())
|
63
|
|
- { for( String phoneNumbers : nums.getPhoneNumbers())
|
|
61
|
+ for (PhoneNumberStorage nums : contacts.values()) {
|
|
62
|
+ for (String phoneNumbers : nums.getPhoneNumbers())
|
64
|
63
|
|
65
|
|
- if (number.equals(phoneNumbers)){
|
66
|
|
- return nums.lookup();
|
67
|
|
- }
|
|
64
|
+ if (number.equals(phoneNumbers)) {
|
|
65
|
+ return nums.lookup();
|
|
66
|
+ }
|
68
|
67
|
}
|
69
|
68
|
return null;
|
70
|
69
|
}
|
71
|
70
|
|
|
71
|
+ public void addmultiple(String name, String... numbers){
|
|
72
|
+ this.name = name;
|
|
73
|
+ for (int i = 0; i < numbers.length; i++){
|
|
74
|
+ contacts.get(name).add(numbers[i]);
|
|
75
|
+ }
|
|
76
|
+ }
|
72
|
77
|
|
73
|
78
|
|
74
|
79
|
}
|