|
@@ -1,10 +1,11 @@
|
1
|
1
|
package com.zipcodewilmington.generic.group;
|
2
|
2
|
|
3
|
3
|
import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
|
|
4
|
+import com.zipcodewilmington.generic.identifiables.Person;
|
4
|
5
|
|
5
|
6
|
import java.io.Serializable;
|
|
7
|
+import java.lang.reflect.Field;
|
6
|
8
|
import java.lang.reflect.ParameterizedType;
|
7
|
|
-import java.lang.reflect.Type;
|
8
|
9
|
import java.util.ArrayList;
|
9
|
10
|
import java.util.List;
|
10
|
11
|
import java.util.function.Predicate;
|
|
@@ -18,46 +19,44 @@ public class Group<
|
18
|
19
|
TypeOfEntity extends IdentifiableInterface<TypeOfId>>
|
19
|
20
|
extends AbstractGroup<TypeOfId, TypeOfEntity> {
|
20
|
21
|
|
21
|
|
- List<TypeOfEntity> group = new ArrayList<>();
|
|
22
|
+ List<TypeOfEntity> group;
|
|
23
|
+
|
|
24
|
+ public Group() {
|
|
25
|
+ this.group = new ArrayList<>();
|
|
26
|
+ }
|
22
|
27
|
|
23
|
28
|
@Override
|
24
|
29
|
public Integer count() {
|
25
|
|
- return group.size();
|
|
30
|
+ return this.group.size();
|
26
|
31
|
}
|
27
|
32
|
|
28
|
33
|
@Override
|
29
|
34
|
public void insert(TypeOfEntity object) {
|
30
|
|
- group.add(object);
|
|
35
|
+ this.group.add(object);
|
31
|
36
|
}
|
32
|
37
|
|
33
|
38
|
@Override
|
34
|
39
|
public void delete(TypeOfEntity object) {
|
35
|
|
- group.remove(object);
|
|
40
|
+ this.group.remove(object);
|
36
|
41
|
}
|
37
|
42
|
|
38
|
43
|
@Override
|
39
|
44
|
public void delete(Serializable serializable) {
|
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
|
|
- }
|
|
45
|
+ while(this.group.iterator().hasNext()) {
|
|
46
|
+ if (this.group.iterator().next().getIdentity() == serializable) {
|
|
47
|
+ this.group.remove(this.group.iterator().next());
|
49
|
48
|
}
|
50
|
49
|
}
|
51
|
50
|
}
|
52
|
51
|
|
53
|
52
|
@Override
|
54
|
53
|
public Boolean has(IdentifiableInterface object) {
|
55
|
|
- return group.contains(object);
|
|
54
|
+ return this.group.contains(object);
|
56
|
55
|
}
|
57
|
56
|
|
58
|
57
|
@Override
|
59
|
58
|
public Boolean has(Serializable serializable) {
|
60
|
|
- for (IdentifiableInterface i : group) {
|
|
59
|
+ for (IdentifiableInterface i : this.group) {
|
61
|
60
|
if (serializable instanceof Number) {
|
62
|
61
|
if (i.getIdentity() == serializable) {
|
63
|
62
|
return true;
|
|
@@ -74,17 +73,32 @@ public class Group<
|
74
|
73
|
|
75
|
74
|
@Override
|
76
|
75
|
public List filter(Predicate<TypeOfEntity> predicate) {
|
77
|
|
- return group.stream().filter(predicate).collect(Collectors.toList());
|
|
76
|
+ return this.group.stream().filter(predicate).collect(Collectors.toList());
|
78
|
77
|
}
|
79
|
78
|
|
80
|
79
|
@Override
|
81
|
80
|
public Class getIdentityType() {
|
82
|
|
- return group.get(0).getIdentityType();
|
|
81
|
+ try {
|
|
82
|
+ Field groupField = Group.class.getDeclaredField("group");
|
|
83
|
+ ParameterizedType groupType = (ParameterizedType) groupField.getGenericType();
|
|
84
|
+ Class<?> groupClass = (Class<?>) groupType.getActualTypeArguments()[0];
|
|
85
|
+ return groupClass;
|
|
86
|
+ } catch (NoSuchFieldException e) {
|
|
87
|
+ e.printStackTrace();
|
|
88
|
+ }
|
|
89
|
+ return null;
|
83
|
90
|
}
|
84
|
91
|
|
85
|
92
|
@Override
|
86
|
93
|
public Class getIdentifiableType() {
|
87
|
|
- return group.get(0).getClass();
|
88
|
|
- }
|
|
94
|
+ try {
|
|
95
|
+ Field groupField = Group.class.getDeclaredField("group");
|
|
96
|
+ ParameterizedType groupType = (ParameterizedType) groupField.getGenericType();
|
|
97
|
+ Class<?> groupClass = (Class<?>) groupType.getActualTypeArguments()[0];
|
|
98
|
+ return groupClass;
|
|
99
|
+ } catch (NoSuchFieldException e) {
|
|
100
|
+ e.printStackTrace();
|
|
101
|
+ }
|
|
102
|
+ return null; }
|
89
|
103
|
|
90
|
104
|
}
|