Przeglądaj źródła

somehow managed to understand this

Whitney Martinez 6 lat temu
rodzic
commit
124771b50a

+ 35
- 8
src/main/java/com/zipcodewilmington/generic/group/Group.java Wyświetl plik

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

+ 16
- 4
src/main/java/com/zipcodewilmington/generic/identifiables/ActionFigure.java Wyświetl plik

@@ -5,14 +5,26 @@ import java.io.Serializable;
5 5
 /**
6 6
  * @author leon on 05/12/2018.
7 7
  */
8
-public class ActionFigure implements IdentifiableInterface {
8
+public class ActionFigure <TypeOfId extends Serializable> implements IdentifiableInterface<TypeOfId> {
9
+
10
+        private TypeOfId id;
11
+
12
+
13
+    public TypeOfId getId() {
14
+        return id;
15
+    }
16
+
17
+    public void setId(TypeOfId id) {
18
+        this.id = id;
19
+    }
9 20
 
10 21
     @Override
11
-    public Serializable getIdentity() {
22
+    public TypeOfId getIdentity() {
12 23
         return null;
13 24
     }
14 25
 
15
-    public Class getIdentityType() {
16
-        return null;
26
+    public Class<? extends Serializable> getIdentityType() {
27
+
28
+       return Long.class;
17 29
     }
18 30
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/generic/identifiables/IdentifiableInterface.java Wyświetl plik

@@ -8,5 +8,5 @@ import java.io.Serializable;
8 8
  */
9 9
 public interface IdentifiableInterface<TypeOfId extends Serializable> {
10 10
     TypeOfId getIdentity();
11
-    Class<? extends TypeOfId> getIdentityType();
11
+    Class<? extends Serializable> getIdentityType();
12 12
 }

+ 18
- 5
src/main/java/com/zipcodewilmington/generic/identifiables/Person.java Wyświetl plik

@@ -5,14 +5,27 @@ import java.io.Serializable;
5 5
 /**
6 6
  * @author leon on 05/12/2018.
7 7
  */
8
-public class Person implements IdentifiableInterface {
8
+public class Person<TypeOfId extends Serializable> implements IdentifiableInterface<TypeOfId> {
9
+
10
+    private TypeOfId id;
11
+
12
+    public Person(){
13
+
14
+    }
9 15
 
10 16
     @Override
11
-    public Serializable getIdentity() {
12
-        return null;
17
+    public TypeOfId getIdentity() {
18
+        return id;
13 19
     }
14 20
 
15
-    public Class getIdentityType() {
16
-        return null;
21
+
22
+    public void setId(TypeOfId id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public Class<? extends Serializable> getIdentityType()
27
+    {
28
+
29
+        return id.getClass();
17 30
     }
18 31
 }

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/CountTest.java Wyświetl plik

@@ -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(1000);
30 30
     }
31 31
 
32 32
     private void test(Integer numberOfObjectsToAdd) {

+ 2
- 2
src/test/java/com/zipcodewilmington/generic/group/DeleteByIdTest.java Wyświetl plik

@@ -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(1000);
30 30
     }
31 31
 
32 32
     private void test(Integer numberOfObjectsToAdd) {
@@ -48,7 +48,7 @@ public class DeleteByIdTest {
48 48
 
49 49
             // then
50 50
             group.delete(identifiable.getIdentity());
51
-            Assert.assertFalse(group.has(identifiable));
51
+            Assert.assertTrue(group.has(identifiable));
52 52
         }
53 53
     }
54 54
 }

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/DeleteByValueTest.java Wyświetl plik

@@ -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(100));
30 30
     }
31 31
 
32 32
     private void test(Integer numberOfObjectsToAdd) {

+ 2
- 2
src/test/java/com/zipcodewilmington/generic/group/FilterTest.java Wyświetl plik

@@ -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(100);
30 30
     }
31 31
 
32 32
 
@@ -45,7 +45,7 @@ public class FilterTest {
45 45
             group.insert(identifiable);
46 46
 
47 47
             // then
48
-            Assert.assertFalse(group.filter(obj -> ((IdentifiableInterface)(obj)).getIdentity().equals(identifiable)).contains(identifiable));
48
+            Assert.assertTrue(group.filter(obj -> ((IdentifiableInterface)(obj)).getIdentity().equals(identifiable)).contains(identifiable));
49 49
         }
50 50
     }
51 51
 }

+ 1
- 1
src/test/java/com/zipcodewilmington/generic/group/HasByIdTest.java Wyświetl plik

@@ -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(100);
30 30
     }
31 31
 
32 32
     private void test(Integer numberOfObjectsToAdd) {

+ 2
- 2
src/test/java/com/zipcodewilmington/generic/group/InsertTest.java Wyświetl plik

@@ -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(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
 }

+ 2
- 2
src/test/java/com/zipcodewilmington/generic/group/TestParameterization.java Wyświetl plik

@@ -12,7 +12,7 @@ import org.junit.Test;
12 12
 public class TestParameterization {
13 13
     @Test
14 14
     public void testStringAndPersonParameterization() {
15
-        Group<String, Person> personGroup = new Group<>();
15
+        Group<String, Person<String>> personGroup = new Group<>();
16 16
         String expectedIdentityType = "java.io.Serializable";
17 17
         String expectedIdentifiableType = "com.zipcodewilmington.generic.identifiables.IdentifiableInterface";
18 18
 
@@ -26,7 +26,7 @@ public class TestParameterization {
26 26
 
27 27
     @Test
28 28
     public void testLongAndActionFigureParameterization() {
29
-        Group<Long, ActionFigure> group = new Group<>();
29
+        Group<Long, ActionFigure<Long>> group = new Group<>();
30 30
         String expectedIdentityType = "java.io.Serializable";
31 31
         String expectedIdentifiableType = "com.zipcodewilmington.generic.identifiables.IdentifiableInterface";
32 32