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