#6 JenniferChao4 - Generic Group Object

Aberto
JenniferChao4 quer mesclar 2 commits de JenniferChao4/GenericGroupObject:master em master

+ 23
- 11
src/main/java/com/zipcodewilmington/generic/group/Group.java Ver arquivo

@@ -3,56 +3,68 @@ 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.Type;
7
+import java.util.ArrayList;
6 8
 import java.util.List;
7 9
 import java.util.function.Predicate;
10
+import java.util.stream.Collectors;
11
+import java.util.stream.Stream;
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<TypeOfId extends Serializable,
17
+        TypeOfEntity extends IdentifiableInterface> extends AbstractGroup{
18
+
19
+    List<TypeOfEntity> list = new ArrayList<>();
20
+
13 21
     @Override
14 22
     public Integer count() {
15
-        return null;
23
+        return list.size();
16 24
     }
17 25
 
18 26
     @Override
19 27
     public void insert(IdentifiableInterface object) {
20
-
28
+        list.add((TypeOfEntity) object);
21 29
     }
22 30
 
23 31
     @Override
24 32
     public void delete(IdentifiableInterface object) {
25
-
33
+        list.remove(object);
26 34
     }
27 35
 
28 36
     @Override
29 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 45
     @Override
34 46
     public Boolean has(IdentifiableInterface object) {
35
-        return null;
47
+        return list.contains(object);
36 48
     }
37 49
 
38 50
     @Override
39 51
     public Boolean has(Serializable serializable) {
40
-        return null;
52
+        return list.contains(serializable);
41 53
     }
42 54
 
43 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 60
     @Override
49 61
     public Class getIdentityType() {
50
-        return null;
62
+        return list.get(0).getIdentity().getClass();
51 63
     }
52 64
 
53 65
     @Override
54 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 Ver arquivo

@@ -7,12 +7,14 @@ import java.io.Serializable;
7 7
  */
8 8
 public class ActionFigure implements IdentifiableInterface {
9 9
 
10
+    Long identity = 0L;
11
+
10 12
     @Override
11 13
     public Serializable getIdentity() {
12
-        return null;
14
+        return identity;
13 15
     }
14 16
 
15 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 Ver arquivo

@@ -7,12 +7,14 @@ import java.io.Serializable;
7 7
  */
8 8
 public class Person implements IdentifiableInterface {
9 9
 
10
+    private String identity = "";
11
+
10 12
     @Override
11 13
     public Serializable getIdentity() {
12
-        return null;
14
+        return identity;
13 15
     }
14 16
 
15 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 Ver arquivo

@@ -26,7 +26,7 @@ public class CountTest {
26 26
 
27 27
     @Test
28 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
     private void test(Integer numberOfObjectsToAdd) {

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/DeleteByIdTest.java Ver arquivo

@@ -26,7 +26,7 @@ public class DeleteByIdTest {
26 26
 
27 27
     @Test
28 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
     private void test(Integer numberOfObjectsToAdd) {

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/DeleteByValueTest.java Ver arquivo

@@ -26,7 +26,7 @@ public class DeleteByValueTest {
26 26
 
27 27
     @Test
28 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
     private void test(Integer numberOfObjectsToAdd) {

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/FilterTest.java Ver arquivo

@@ -26,7 +26,7 @@ public class FilterTest {
26 26
 
27 27
     @Test
28 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 Ver arquivo

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

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/HasByIdTest.java Ver arquivo

@@ -26,7 +26,7 @@ public class HasByIdTest {
26 26
 
27 27
     @Test
28 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
     private void test(Integer numberOfObjectsToAdd) {

+ 2
- 2
src/test/java/com/zipcodewilmington/generic/group/InsertTest.java Ver arquivo

@@ -26,7 +26,7 @@ public class InsertTest {
26 26
 
27 27
     @Test
28 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
     private void test(Integer numberOfObjectsToAdd) {
@@ -44,7 +44,7 @@ public class InsertTest {
44 44
             group.insert(identifiable);
45 45
 
46 46
             // then
47
-            Assert.assertFalse(group.has(identifiable));
47
+            Assert.assertTrue(group.has(identifiable));
48 48
         }
49 49
     }
50 50
 }