|
|
@@ -1,10 +1,15 @@
|
|
1
|
1
|
package com.zipcodewilmington.generic.group;
|
|
2
|
2
|
|
|
|
3
|
+import com.sun.javafx.tools.packager.Param;
|
|
3
|
4
|
import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
|
|
4
|
5
|
|
|
5
|
6
|
import java.io.Serializable;
|
|
|
7
|
+import java.lang.reflect.Field;
|
|
|
8
|
+import java.lang.reflect.ParameterizedType;
|
|
|
9
|
+import java.lang.reflect.Type;
|
|
6
|
10
|
import java.util.*;
|
|
7
|
11
|
import java.util.function.Predicate;
|
|
|
12
|
+import java.util.stream.Collectors;
|
|
8
|
13
|
|
|
9
|
14
|
/**
|
|
10
|
15
|
* @author leon on 06/12/2018.
|
|
|
@@ -33,9 +38,7 @@ public class Group<TypeOfId extends Serializable,
|
|
33
|
38
|
|
|
34
|
39
|
@Override
|
|
35
|
40
|
public void delete(Serializable serializable) {
|
|
36
|
|
- for (IdentifiableInterface i : list)
|
|
37
|
|
- if (i.getIdentity().equals(serializable))
|
|
38
|
|
- list.remove(i);
|
|
|
41
|
+ list.removeIf(e -> e.getIdentity().equals(serializable));
|
|
39
|
42
|
}
|
|
40
|
43
|
|
|
41
|
44
|
@Override
|
|
|
@@ -53,18 +56,27 @@ public class Group<TypeOfId extends Serializable,
|
|
53
|
56
|
|
|
54
|
57
|
@Override
|
|
55
|
58
|
public List filter(Predicate predicate) {
|
|
56
|
|
- list.removeIf(predicate);
|
|
57
|
|
- return list;
|
|
|
59
|
+ return (List) list.stream().filter(predicate).collect(Collectors.toList());
|
|
58
|
60
|
}
|
|
59
|
61
|
|
|
60
|
62
|
@Override
|
|
61
|
|
- public Class getIdentityType() {
|
|
62
|
|
- return null;
|
|
|
63
|
+ public Class<? extends TypeOfId> getIdentityType() {
|
|
|
64
|
+ Class clazz = getClass(); //class com.zipcodewilmington.generic.group.Group
|
|
|
65
|
+ Type type = clazz.getGenericSuperclass(); //com.zipcodewilmington.generic.group.AbstractGroup<TypeOfId, TypeOfEntity>
|
|
|
66
|
+ ParameterizedType pt = (ParameterizedType) type; //com.zipcodewilmington.generic.group.AbstractGroup<TypeOfId, TypeOfEntity>
|
|
|
67
|
+ Type[] types = pt.getActualTypeArguments(); //[Ljava.lang.reflect.Type;@6073f712
|
|
|
68
|
+ Type type1 = types[0]; //TypeOfId
|
|
|
69
|
+ return (Class) type1.getClass();
|
|
63
|
70
|
}
|
|
64
|
71
|
|
|
65
|
72
|
@Override
|
|
66
|
|
- public Class getIdentifiableType() {
|
|
67
|
|
- return null;
|
|
|
73
|
+ public Class<? extends TypeOfEntity> getIdentifiableType() {
|
|
|
74
|
+ Class clazz = getClass(); //class com.zipcodewilmington.generic.group.Group
|
|
|
75
|
+ Type type = clazz.getGenericSuperclass(); //com.zipcodewilmington.generic.group.AbstractGroup<TypeOfId, TypeOfEntity>
|
|
|
76
|
+ ParameterizedType pt = (ParameterizedType) type; //com.zipcodewilmington.generic.group.AbstractGroup<TypeOfId, TypeOfEntity>
|
|
|
77
|
+ Type[] types = pt.getActualTypeArguments(); //[Ljava.lang.reflect.Type;@6073f712
|
|
|
78
|
+ Type type1 = types[1]; //TypeOfEntity
|
|
|
79
|
+ return (Class) type1.getClass();
|
|
68
|
80
|
}
|
|
69
|
81
|
|
|
70
|
82
|
}
|