|
@@ -1,8 +1,7 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
|
-import java.util.Map;
|
3
|
|
-import java.util.Set;
|
4
|
|
-import java.util.SortedMap;
|
|
2
|
+import java.util.*;
|
5
|
3
|
import java.util.TreeMap;
|
|
4
|
+import java.util.Set;
|
6
|
5
|
|
7
|
6
|
/**
|
8
|
7
|
* Created by leon on 1/23/18.
|
|
@@ -11,59 +10,61 @@ public class PhoneBook {
|
11
|
10
|
|
12
|
11
|
String name;
|
13
|
12
|
String number;
|
|
13
|
+ ArrayList<String> numbersList = new ArrayList<>();
|
14
|
14
|
|
15
|
15
|
|
16
|
|
- private Map<String, String> contactsList;
|
|
16
|
+ private TreeMap contactsList;
|
17
|
17
|
|
18
|
|
- public PhoneBook(){
|
19
|
|
- this.contactsList = new TreeMap<String, String>();
|
20
|
|
- contactsList.put("Pete Jones", "2678849087");
|
21
|
|
- contactsList.put("Ron Burgundy", "5604329932");
|
22
|
|
- contactsList.put("Nala Bits", "2345578122");
|
|
18
|
+ public PhoneBook() {
|
|
19
|
+ this.contactsList = new TreeMap<>();
|
23
|
20
|
|
24
|
21
|
}
|
25
|
|
- public Map<String, String> getContactsList(){
|
|
22
|
+
|
|
23
|
+ public Map<String, ArrayList> getContactsList() {
|
26
|
24
|
return contactsList;
|
27
|
25
|
|
28
|
26
|
}
|
29
|
27
|
|
30
|
|
- public void addContact(String name, String number) {
|
|
28
|
+ public String addContact(String name, String number) {
|
31
|
29
|
if (!contactsList.containsKey(name)) {
|
32
|
30
|
contactsList.put(name, number);
|
33
|
|
- System.out.println("New contact " + name + " has been added");
|
34
|
|
- } else {
|
35
|
|
- System.out.println("Contact already exists");
|
36
|
31
|
}
|
|
32
|
+ return "";
|
37
|
33
|
}
|
38
|
34
|
|
39
|
|
- public void removeContact(String name) {
|
|
35
|
+ public String removeContact(String name) {
|
40
|
36
|
if (contactsList.containsKey(name)) {
|
41
|
37
|
contactsList.remove(name);
|
42
|
|
- System.out.println("Contact has been removed");
|
43
|
|
- } else {
|
44
|
|
- System.out.println("No " + name + " contact exists");
|
45
|
38
|
}
|
|
39
|
+ return "";
|
46
|
40
|
}
|
47
|
41
|
|
48
|
|
- public String lookUpContactByName(String name){
|
49
|
|
- return contactsList.get(name) == null ? "Sorry name not found" : contactsList.get(name);
|
50
|
|
- }
|
51
|
42
|
|
52
|
|
- public String listAllByName(String strings) {
|
53
|
|
- Set nameSet = contactsList.keySet();
|
54
|
|
- for (Object names : nameSet) {
|
55
|
|
- return names.toString();
|
|
43
|
+ public String listAllNamesAndNumbers() {
|
|
44
|
+ Set listingAll = contactsList.entrySet();
|
|
45
|
+ return listingAll.toString();
|
|
46
|
+ /*String getEntries = new String();
|
|
47
|
+ for (Object allEntries : listingAll) {
|
|
48
|
+ if(listingAll.equals());*/
|
56
|
49
|
}
|
57
|
50
|
|
58
|
51
|
|
59
|
|
- public String listAllNamesAndNumbers(){
|
60
|
|
- Set listingAll = contactsList.entrySet();
|
61
|
|
- for (Object allEntries : listingAll )
|
62
|
|
- return allEntries.toString();
|
|
52
|
+
|
|
53
|
+ public String reverseLookUp() {
|
|
54
|
+ Set<String> listingReverse = contactsList.keySet();
|
|
55
|
+ for (String allEntries : listingReverse) {
|
|
56
|
+ if(listingReverse.contains(allEntries.equals(number))) {
|
|
57
|
+ return allEntries;
|
|
58
|
+ }
|
63
|
59
|
|
64
|
60
|
}
|
|
61
|
+ return "";
|
65
|
62
|
}
|
66
|
63
|
}
|
67
|
64
|
|
68
|
65
|
|
69
|
66
|
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|