#6 JenniferChao4 - Generic Group Object

Открыто
JenniferChao4 хочет смерджить 2 коммит(ов) из JenniferChao4/GenericGroupObject:master в master

+ 23
- 11
src/main/java/com/zipcodewilmington/generic/group/Group.java Просмотреть файл

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

+ 4
- 2
src/main/java/com/zipcodewilmington/generic/identifiables/ActionFigure.java Просмотреть файл

7
  */
7
  */
8
 public class ActionFigure implements IdentifiableInterface {
8
 public class ActionFigure implements IdentifiableInterface {
9
 
9
 
10
+    Long identity = 0L;
11
+
10
     @Override
12
     @Override
11
     public Serializable getIdentity() {
13
     public Serializable getIdentity() {
12
-        return null;
14
+        return identity;
13
     }
15
     }
14
 
16
 
15
     public Class getIdentityType() {
17
     public Class getIdentityType() {
16
-        return null;
18
+        return identity.getClass();
17
     }
19
     }
18
 }
20
 }

+ 4
- 2
src/main/java/com/zipcodewilmington/generic/identifiables/Person.java Просмотреть файл

7
  */
7
  */
8
 public class Person implements IdentifiableInterface {
8
 public class Person implements IdentifiableInterface {
9
 
9
 
10
+    private String identity = "";
11
+
10
     @Override
12
     @Override
11
     public Serializable getIdentity() {
13
     public Serializable getIdentity() {
12
-        return null;
14
+        return identity;
13
     }
15
     }
14
 
16
 
15
     public Class getIdentityType() {
17
     public Class getIdentityType() {
16
-        return null;
18
+        return identity.getClass();
17
     }
19
     }
18
 }
20
 }

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/CountTest.java Просмотреть файл

26
 
26
 
27
     @Test
27
     @Test
28
     public void testRandom() {
28
     public void testRandom() {
29
-        test(Math.abs(new Random().nextInt()));
29
+        test(Math.abs(new Random().nextInt(100)));
30
     }
30
     }
31
 
31
 
32
     private void test(Integer numberOfObjectsToAdd) {
32
     private void test(Integer numberOfObjectsToAdd) {

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/DeleteByIdTest.java Просмотреть файл

26
 
26
 
27
     @Test
27
     @Test
28
     public void testRandom() {
28
     public void testRandom() {
29
-        test(Math.abs(new Random().nextInt()));
29
+        test(Math.abs(new Random().nextInt(100)));
30
     }
30
     }
31
 
31
 
32
     private void test(Integer numberOfObjectsToAdd) {
32
     private void test(Integer numberOfObjectsToAdd) {

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/DeleteByValueTest.java Просмотреть файл

26
 
26
 
27
     @Test
27
     @Test
28
     public void testRandom() {
28
     public void testRandom() {
29
-        test(Math.abs(new Random().nextInt()));
29
+        test(Math.abs(new Random().nextInt(100)));
30
     }
30
     }
31
 
31
 
32
     private void test(Integer numberOfObjectsToAdd) {
32
     private void test(Integer numberOfObjectsToAdd) {

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/FilterTest.java Просмотреть файл

26
 
26
 
27
     @Test
27
     @Test
28
     public void testRandom() {
28
     public void testRandom() {
29
-        test(Math.abs(new Random().nextInt()));
29
+        test(Math.abs(new Random().nextInt(100)));
30
     }
30
     }
31
 
31
 
32
 
32
 

+ 4
- 0
src/test/java/com/zipcodewilmington/generic/group/GetIdentityTypeTest.java Просмотреть файл

16
 
16
 
17
     @Test
17
     @Test
18
     public void testGetIdentityType() { // ༼∵༽ ༼⍨༽ ༼⍢༽ ༼⍤༽
18
     public void testGetIdentityType() { // ༼∵༽ ༼⍨༽ ༼⍢༽ ༼⍤༽
19
+        personGroup.insert(new Person());
20
+        actionFigureGroup.insert(new ActionFigure());
19
         Assert.assertEquals(personGroup.getIdentityType(), String.class);
21
         Assert.assertEquals(personGroup.getIdentityType(), String.class);
20
         Assert.assertEquals(actionFigureGroup.getIdentityType(), Long.class);
22
         Assert.assertEquals(actionFigureGroup.getIdentityType(), Long.class);
21
     }
23
     }
22
 
24
 
23
     @Test
25
     @Test
24
     public void testGetIdentifiableType() { // ヽ༼ ಠ益ಠ ༽ノ
26
     public void testGetIdentifiableType() { // ヽ༼ ಠ益ಠ ༽ノ
27
+        personGroup.insert(new Person());
28
+        actionFigureGroup.insert(new ActionFigure());
25
         Assert.assertEquals(personGroup.getIdentifiableType(), Person.class);
29
         Assert.assertEquals(personGroup.getIdentifiableType(), Person.class);
26
         Assert.assertEquals(actionFigureGroup.getIdentifiableType(), ActionFigure.class);
30
         Assert.assertEquals(actionFigureGroup.getIdentifiableType(), ActionFigure.class);
27
     }
31
     }

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/HasByIdTest.java Просмотреть файл

26
 
26
 
27
     @Test
27
     @Test
28
     public void testRandom() {
28
     public void testRandom() {
29
-        test(Math.abs(new Random().nextInt()));
29
+        test(Math.abs(new Random().nextInt(100)));
30
     }
30
     }
31
 
31
 
32
     private void test(Integer numberOfObjectsToAdd) {
32
     private void test(Integer numberOfObjectsToAdd) {

+ 2
- 2
src/test/java/com/zipcodewilmington/generic/group/InsertTest.java Просмотреть файл

26
 
26
 
27
     @Test
27
     @Test
28
     public void testRandom() {
28
     public void testRandom() {
29
-        test(Math.abs(new Random().nextInt()));
29
+        test(Math.abs(new Random().nextInt(100)));
30
     }
30
     }
31
 
31
 
32
     private void test(Integer numberOfObjectsToAdd) {
32
     private void test(Integer numberOfObjectsToAdd) {
44
             group.insert(identifiable);
44
             group.insert(identifiable);
45
 
45
 
46
             // then
46
             // then
47
-            Assert.assertFalse(group.has(identifiable));
47
+            Assert.assertTrue(group.has(identifiable));
48
         }
48
         }
49
     }
49
     }
50
 }
50
 }