|
@@ -1,9 +1,6 @@
|
1
|
1
|
package rocks.zipcode.io.quiz4.collections;
|
2
|
2
|
|
3
|
|
-import java.util.HashSet;
|
4
|
|
-import java.util.Iterator;
|
5
|
|
-import java.util.Set;
|
6
|
|
-import java.util.Spliterator;
|
|
3
|
+import java.util.*;
|
7
|
4
|
import java.util.function.Consumer;
|
8
|
5
|
|
9
|
6
|
import static com.sun.jmx.snmp.ThreadContext.contains;
|
|
@@ -12,56 +9,48 @@ import static com.sun.jmx.snmp.ThreadContext.contains;
|
12
|
9
|
* @author leon on 11/12/2018.
|
13
|
10
|
*/
|
14
|
11
|
public class SimpleStringGroup implements Iterable{
|
|
12
|
+
|
|
13
|
+ List<String> val = new ArrayList<>();
|
15
|
14
|
public SimpleStringGroup() {
|
16
|
15
|
//throw new UnsupportedOperationException("Method not yet implemented");
|
17
|
16
|
}
|
18
|
17
|
|
19
|
|
- private final Set<String> set = new HashSet<>();
|
20
|
|
-
|
21
|
|
-
|
22
|
18
|
public Integer count() {
|
23
|
|
- return set.size();
|
|
19
|
+ return val.size();
|
24
|
20
|
}
|
25
|
21
|
|
26
|
22
|
public void insert(String string) {
|
27
|
|
- if (!contains(string)) {
|
28
|
|
- set.add(string);
|
29
|
|
- }
|
|
23
|
+// if (!contains(string)) {
|
|
24
|
+ val.add(string);
|
30
|
25
|
}
|
31
|
26
|
|
32
|
27
|
public Boolean has(String valueToInsert) {
|
33
|
|
- return set.contains(valueToInsert);
|
|
28
|
+ if (val.contains(valueToInsert)){
|
|
29
|
+ return true;
|
|
30
|
+ }
|
|
31
|
+ return false;
|
34
|
32
|
}
|
35
|
33
|
|
36
|
34
|
public String fetch(int indexOfValue) {
|
37
|
|
- //return set.add(indexOfValue);
|
38
|
|
- return String.valueOf(set.equals(indexOfValue));
|
39
|
|
- //return null;
|
|
35
|
+ return val.get(indexOfValue);
|
|
36
|
+
|
40
|
37
|
}
|
41
|
38
|
|
42
|
39
|
public void delete(String valueToInsert) {
|
43
|
|
- set.remove(valueToInsert);
|
|
40
|
+ val.remove(valueToInsert);
|
44
|
41
|
}
|
45
|
42
|
|
46
|
43
|
public void clear() {
|
47
|
|
- set.clear();
|
|
44
|
+ val.clear();
|
48
|
45
|
}
|
49
|
46
|
|
50
|
|
- public void get() {
|
51
|
|
- set.size();
|
52
|
|
- }
|
53
|
|
-
|
54
|
47
|
@Override
|
55
|
48
|
public Iterator iterator() {
|
56
|
|
- return null;
|
|
49
|
+ return val.iterator();
|
57
|
50
|
}
|
58
|
51
|
|
59
|
52
|
@Override
|
60
|
53
|
public void forEach(Consumer action) {
|
61
|
54
|
}
|
62
|
55
|
|
63
|
|
- @Override
|
64
|
|
- public Spliterator spliterator() {
|
65
|
|
- return null;
|
66
|
|
- }
|
67
|
56
|
}
|