Browse Source

59 of 234

Nick Satinover 6 years ago
parent
commit
9940e853af

+ 22
- 5
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java View File

1
 package rocks.zipcode.io.quiz4.collections;
1
 package rocks.zipcode.io.quiz4.collections;
2
 
2
 
3
+import java.util.ArrayList;
4
+import java.util.Collection;
5
+import java.util.Iterator;
6
+
3
 /**
7
 /**
4
  * @author leon on 11/12/2018.
8
  * @author leon on 11/12/2018.
5
  */
9
  */
6
-public class SimpleStringGroup {
10
+public class SimpleStringGroup implements Iterable {
11
+    ArrayList<String> s = new ArrayList<>();
12
+
7
     public SimpleStringGroup() {
13
     public SimpleStringGroup() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
14
+        // throw new UnsupportedOperationException("Method not yet implemented");
9
     }
15
     }
10
 
16
 
11
     public Integer count() {
17
     public Integer count() {
12
-        return null;
18
+        return s.size();
13
     }
19
     }
14
 
20
 
15
     public void insert(String string) {
21
     public void insert(String string) {
22
+        s.add(string);
16
     }
23
     }
17
 
24
 
18
     public Boolean has(String valueToInsert) {
25
     public Boolean has(String valueToInsert) {
19
-        return null;
26
+        if (s.contains(valueToInsert)){
27
+            return true;
28
+        }
29
+        return false;
20
     }
30
     }
21
 
31
 
22
     public String fetch(int indexOfValue) {
32
     public String fetch(int indexOfValue) {
23
-        return null;
33
+        return s.get(indexOfValue);
24
     }
34
     }
25
 
35
 
26
     public void delete(String valueToInsert) {
36
     public void delete(String valueToInsert) {
37
+        s.remove(valueToInsert);
27
     }
38
     }
28
 
39
 
29
     public void clear() {
40
     public void clear() {
41
+        s.clear();
42
+    }
43
+
44
+    @Override
45
+    public Iterator iterator() {
46
+        return s.iterator();
30
     }
47
     }
31
 }
48
 }