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