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