|
@@ -3,56 +3,89 @@ package com.zipcodewilmington.generic.group;
|
3
|
3
|
import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
|
4
|
4
|
|
5
|
5
|
import java.io.Serializable;
|
|
6
|
+import java.util.ArrayList;
|
|
7
|
+import java.util.Iterator;
|
6
|
8
|
import java.util.List;
|
7
|
9
|
import java.util.function.Predicate;
|
|
10
|
+import java.util.function.Predicate;
|
|
11
|
+import java.util.function.Supplier;
|
|
12
|
+import java.util.stream.Collectors;
|
8
|
13
|
|
9
|
14
|
/**
|
10
|
15
|
* @author leon on 06/12/2018.
|
11
|
16
|
*/
|
12
|
|
-public class Group<ChangeThisTypeRespectively,ChangeThisOneToo> extends AbstractGroup{
|
13
|
|
- @Override
|
|
17
|
+public class Group<TypeOfId extends Serializable ,TypeOfEntity extends IdentifiableInterface<TypeOfId>>
|
|
18
|
+ extends AbstractGroup<TypeOfId, TypeOfEntity>
|
|
19
|
+{
|
|
20
|
+ private ArrayList<TypeOfEntity> list;
|
|
21
|
+
|
|
22
|
+public Group()
|
|
23
|
+ {
|
|
24
|
+ this.list = new ArrayList<>();
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+@Override
|
14
|
29
|
public Integer count() {
|
15
|
|
- return null;
|
|
30
|
+ return list.size();
|
16
|
31
|
}
|
17
|
32
|
|
18
|
33
|
@Override
|
19
|
|
- public void insert(IdentifiableInterface object) {
|
20
|
|
-
|
|
34
|
+ public void insert(IdentifiableInterface object)
|
|
35
|
+ {
|
|
36
|
+ list.add((TypeOfEntity) object);
|
21
|
37
|
}
|
22
|
38
|
|
23
|
39
|
@Override
|
24
|
|
- public void delete(IdentifiableInterface object) {
|
25
|
|
-
|
|
40
|
+ public void delete(IdentifiableInterface object)
|
|
41
|
+ {
|
|
42
|
+ list.remove(object);
|
26
|
43
|
}
|
27
|
44
|
|
28
|
45
|
@Override
|
29
|
|
- public void delete(Serializable serializable) {
|
|
46
|
+ public void delete(Serializable serializable)
|
|
47
|
+ {
|
|
48
|
+ Iterator iterator = list.iterator();
|
|
49
|
+ while (iterator.hasNext()){
|
|
50
|
+ IdentifiableInterface next = (IdentifiableInterface) iterator.next();
|
|
51
|
+ if(next.getIdentity().equals(serializable)) iterator.remove();
|
|
52
|
+ }
|
30
|
53
|
|
31
|
54
|
}
|
32
|
55
|
|
33
|
56
|
@Override
|
34
|
57
|
public Boolean has(IdentifiableInterface object) {
|
35
|
|
- return null;
|
|
58
|
+ for (IdentifiableInterface id : list) {
|
|
59
|
+ if (list.contains(id)) return true;
|
|
60
|
+ }
|
|
61
|
+ return false;
|
36
|
62
|
}
|
37
|
63
|
|
38
|
64
|
@Override
|
39
|
65
|
public Boolean has(Serializable serializable) {
|
40
|
|
- return null;
|
|
66
|
+ Iterator iterator = list.iterator();
|
|
67
|
+ while (iterator.hasNext()){
|
|
68
|
+ IdentifiableInterface next = (IdentifiableInterface) iterator.next();
|
|
69
|
+ if(next.getIdentity().equals(serializable)) return true;
|
|
70
|
+ }
|
|
71
|
+ return false;
|
41
|
72
|
}
|
42
|
73
|
|
43
|
74
|
@Override
|
44
|
75
|
public List filter(Predicate predicate) {
|
45
|
|
- return null;
|
|
76
|
+ return (ArrayList<TypeOfEntity>)list.stream()
|
|
77
|
+ .filter(predicate)
|
|
78
|
+ .collect(Collectors.toList());
|
46
|
79
|
}
|
47
|
80
|
|
48
|
81
|
@Override
|
49
|
82
|
public Class getIdentityType() {
|
50
|
|
- return null;
|
|
83
|
+ return list.getClass();
|
51
|
84
|
}
|
52
|
85
|
|
53
|
86
|
@Override
|
54
|
87
|
public Class getIdentifiableType() {
|
55
|
|
- return null;
|
|
88
|
+ return this.getClass().getEnclosingClass();
|
56
|
89
|
}
|
57
|
90
|
|
58
|
91
|
}
|