|
@@ -1,7 +1,9 @@
|
1
|
1
|
package rocks.zipcode.io.quiz4.collections;
|
2
|
2
|
|
|
3
|
+import java.util.ArrayList;
|
3
|
4
|
import java.util.Collection;
|
4
|
5
|
import java.util.Iterator;
|
|
6
|
+import java.util.List;
|
5
|
7
|
|
6
|
8
|
/**
|
7
|
9
|
* @author leon on 11/12/2018.
|
|
@@ -18,6 +20,7 @@ public class SimpleStringGroup implements Iterable, Collection {
|
18
|
20
|
this.indexOfValue = indexOfValue;
|
19
|
21
|
}
|
20
|
22
|
|
|
23
|
+ List<String> list = new ArrayList<>();
|
21
|
24
|
SimpleStringGroup group = new SimpleStringGroup();
|
22
|
25
|
|
23
|
26
|
public SimpleStringGroup() {
|
|
@@ -29,23 +32,23 @@ public class SimpleStringGroup implements Iterable, Collection {
|
29
|
32
|
}
|
30
|
33
|
|
31
|
34
|
public void insert(String string) {
|
32
|
|
- this.string = string;
|
|
35
|
+ list.add(string);
|
33
|
36
|
}
|
34
|
37
|
|
35
|
38
|
public Boolean has(String valueToInsert) {
|
36
|
|
- if(group.contains(valueToInsert)){
|
|
39
|
+ if(list.contains(valueToInsert)){
|
37
|
40
|
return true;
|
38
|
41
|
}
|
39
|
42
|
return false;
|
40
|
43
|
}
|
41
|
44
|
|
42
|
45
|
public String fetch(int indexOfValue) {
|
43
|
|
- return String.valueOf(group.contains(indexOfValue));
|
|
46
|
+ return String.valueOf(list.contains(indexOfValue));
|
44
|
47
|
|
45
|
48
|
}
|
46
|
49
|
|
47
|
50
|
public void delete(String valueToInsert) {
|
48
|
|
- this.valueToInsert = valueToInsert;
|
|
51
|
+ group.delete(valueToInsert);
|
49
|
52
|
}
|
50
|
53
|
|
51
|
54
|
@Override
|
|
@@ -55,12 +58,13 @@ public class SimpleStringGroup implements Iterable, Collection {
|
55
|
58
|
|
56
|
59
|
@Override
|
57
|
60
|
public boolean isEmpty() {
|
58
|
|
- return true;
|
|
61
|
+
|
|
62
|
+ return list.isEmpty();
|
59
|
63
|
}
|
60
|
64
|
|
61
|
65
|
@Override
|
62
|
66
|
public boolean contains(Object o) {
|
63
|
|
- if(string.equals(o)){
|
|
67
|
+ if(list.equals(o)){
|
64
|
68
|
return true;
|
65
|
69
|
}
|
66
|
70
|
return false;
|
|
@@ -74,7 +78,7 @@ public class SimpleStringGroup implements Iterable, Collection {
|
74
|
78
|
@Override
|
75
|
79
|
public boolean add(Object o) {
|
76
|
80
|
|
77
|
|
- return group.add(o);
|
|
81
|
+ return true;
|
78
|
82
|
}
|
79
|
83
|
|
80
|
84
|
@Override
|