Browse Source

removed unnecessary comments

Carolynn Vansant 6 years ago
parent
commit
6e6340796a

+ 7
- 14
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

6
  */
6
  */
7
 public class PhoneBook {
7
 public class PhoneBook {
8
 
8
 
9
-    //instance variable
10
     private TreeMap<String, ArrayList<String>> treeMap;
9
     private TreeMap<String, ArrayList<String>> treeMap;
11
 
10
 
12
-
13
-    // void "no arguments" constructor -creates empty map
14
     public PhoneBook() {
11
     public PhoneBook() {
15
         this.treeMap= new TreeMap<String, ArrayList<String>>();
12
         this.treeMap= new TreeMap<String, ArrayList<String>>();
16
     }
13
     }
17
 
14
 
18
-    // single argument constructor -type Map -creates new map w/ same key/value mappings as argument
19
     public PhoneBook(TreeMap treeMap) {
15
     public PhoneBook(TreeMap treeMap) {
20
         this.treeMap = treeMap;
16
         this.treeMap = treeMap;
21
     }
17
     }
22
 
18
 
23
-    //add a name & number entry, add number
24
     public void addEntry(String name, ArrayList<String> number) {
19
     public void addEntry(String name, ArrayList<String> number) {
25
         if (!treeMap.containsKey(name)) {
20
         if (!treeMap.containsKey(name)) {
26
             treeMap.put(name, number);
21
             treeMap.put(name, number);
27
         }
22
         }
28
     }
23
     }
29
 
24
 
30
-    //add numbers to existing entries
25
+
31
     public void addNumberToEntry(String name, String number) {
26
     public void addNumberToEntry(String name, String number) {
32
         for (Map.Entry<String, ArrayList<String>> entry : treeMap.entrySet()) {
27
         for (Map.Entry<String, ArrayList<String>> entry : treeMap.entrySet()) {
33
             if (name.equals(entry.getKey())) {
28
             if (name.equals(entry.getKey())) {
37
         }
32
         }
38
     }
33
     }
39
 
34
 
40
-    //remove numbers from existing entries
35
+
41
     public void removeNumberFromEntry(String name, String number) {
36
     public void removeNumberFromEntry(String name, String number) {
42
         for (Map.Entry<String, ArrayList<String>> entry : treeMap.entrySet()) {
37
         for (Map.Entry<String, ArrayList<String>> entry : treeMap.entrySet()) {
43
             if (entry.getKey().equals(name)) {
38
             if (entry.getKey().equals(name)) {
48
         }
43
         }
49
     }
44
     }
50
 
45
 
51
-    //remove entire entry
46
+
52
     public void removeEntry(String name) {
47
     public void removeEntry(String name) {
53
             treeMap.remove(name);
48
             treeMap.remove(name);
54
     }
49
     }
55
 
50
 
56
-    //lookup: find phone number from name
51
+
57
     public ArrayList<String> lookup(String name) {
52
     public ArrayList<String> lookup(String name) {
58
         return treeMap.get(name);
53
         return treeMap.get(name);
59
     }
54
     }
60
 
55
 
61
-    //reverse lookup: find name from number
56
+
62
     public String reverseLookup (String number) {
57
     public String reverseLookup (String number) {
63
         String name = "";
58
         String name = "";
64
         for(Map.Entry<String, ArrayList<String>> entry: treeMap.entrySet()) {
59
         for(Map.Entry<String, ArrayList<String>> entry: treeMap.entrySet()) {
65
             ArrayList<String> value = entry.getValue();
60
             ArrayList<String> value = entry.getValue();
66
             for(String revnumber: value) {
61
             for(String revnumber: value) {
67
-                if(number.contains(revnumber)) {
68
-                    name = entry.getKey();
69
-                }
62
+                if(number.contains(revnumber)) name = entry.getKey();
70
             }
63
             }
71
         }
64
         }
72
         return name;
65
         return name;
73
     }
66
     }
74
 
67
 
75
-    //print out all of the entries in PhoneBook
68
+
76
     public String display(){
69
     public String display(){
77
         StringBuilder printOut = new StringBuilder();
70
         StringBuilder printOut = new StringBuilder();
78
         for(Map.Entry<String, ArrayList<String>> entry: treeMap.entrySet()) {
71
         for(Map.Entry<String, ArrayList<String>> entry: treeMap.entrySet()) {

+ 1
- 7
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

2
 
2
 
3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
-import sun.nio.cs.ext.SJIS;
6
-
7
 import java.util.ArrayList;
5
 import java.util.ArrayList;
8
 import java.util.Arrays;
6
 import java.util.Arrays;
9
-import java.util.TreeMap;
10
 
7
 
11
 /**
8
 /**
12
  * Created by leon on 1/23/18.
9
  * Created by leon on 1/23/18.
13
  */
10
  */
14
 public class PhoneBookTest {
11
 public class PhoneBookTest {
12
+
15
     @Test
13
     @Test
16
     public void testDefaultConstructor() {
14
     public void testDefaultConstructor() {
17
         PhoneBook book = new PhoneBook();
15
         PhoneBook book = new PhoneBook();
70
 
68
 
71
     @Test
69
     @Test
72
     public void testRemoveEntry() {
70
     public void testRemoveEntry() {
73
-
74
         //Given
71
         //Given
75
         PhoneBook book = new PhoneBook();
72
         PhoneBook book = new PhoneBook();
76
         ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2222","302-555-3456"));
73
         ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2222","302-555-3456"));
86
 
83
 
87
     @Test
84
     @Test
88
     public void testLookup(){
85
     public void testLookup(){
89
-        //To test if lookup returns all of the person's phone numbers
90
         //Given
86
         //Given
91
         PhoneBook book = new PhoneBook();
87
         PhoneBook book = new PhoneBook();
92
         ArrayList<String> expectedNumber = new ArrayList<String>(Arrays.asList("302-555-2223","302-555-3456"));
88
         ArrayList<String> expectedNumber = new ArrayList<String>(Arrays.asList("302-555-2223","302-555-3456"));
99
 
95
 
100
     @Test
96
     @Test
101
     public void testLookup2(){
97
     public void testLookup2(){
102
-        //To test if lookup picks out the right person when there are multiple entries
103
         //Given
98
         //Given
104
         PhoneBook book = new PhoneBook();
99
         PhoneBook book = new PhoneBook();
105
         ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2223"));
100
         ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2223"));
115
 
110
 
116
     @Test
111
     @Test
117
     public void testreverseLookup(){
112
     public void testreverseLookup(){
118
-        // to test if right person is returned when searching by one of multiple phone numbers
119
         //Given
113
         //Given
120
         PhoneBook book = new PhoneBook();
114
         PhoneBook book = new PhoneBook();
121
         ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2223","302-555-5555"));
115
         ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2223","302-555-5555"));