Pārlūkot izejas kodu

commited changes

Soujanya Buragapu 5 gadus atpakaļ
vecāks
revīzija
e5070aa772

+ 46
- 13
src/main/java/com/zipcodewilmington/generic/group/Group.java Parādīt failu

@@ -3,56 +3,89 @@ 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.Iterator;
6 8
 import java.util.List;
7 9
 import java.util.function.Predicate;
10
+import java.util.function.Predicate;
11
+import java.util.function.Supplier;
12
+import java.util.stream.Collectors;
8 13
 
9 14
 /**
10 15
  * @author leon on 06/12/2018.
11 16
  */
12
-public class Group<ChangeThisTypeRespectively,ChangeThisOneToo> extends AbstractGroup{
13
-    @Override
17
+public class Group<TypeOfId extends Serializable ,TypeOfEntity extends IdentifiableInterface<TypeOfId>>
18
+        extends AbstractGroup<TypeOfId, TypeOfEntity>
19
+{
20
+    private ArrayList<TypeOfEntity> list;
21
+
22
+public Group()
23
+        {
24
+        this.list = new ArrayList<>();
25
+        }
26
+
27
+
28
+@Override
14 29
     public Integer count() {
15
-        return null;
30
+        return list.size();
16 31
     }
17 32
 
18 33
     @Override
19
-    public void insert(IdentifiableInterface object) {
20
-
34
+    public void insert(IdentifiableInterface object)
35
+    {
36
+        list.add((TypeOfEntity) object);
21 37
     }
22 38
 
23 39
     @Override
24
-    public void delete(IdentifiableInterface object) {
25
-
40
+    public void delete(IdentifiableInterface object)
41
+    {
42
+        list.remove(object);
26 43
     }
27 44
 
28 45
     @Override
29
-    public void delete(Serializable serializable) {
46
+    public void delete(Serializable serializable)
47
+    {
48
+        Iterator iterator = list.iterator();
49
+        while (iterator.hasNext()){
50
+            IdentifiableInterface next = (IdentifiableInterface) iterator.next();
51
+            if(next.getIdentity().equals(serializable)) iterator.remove();
52
+        }
30 53
 
31 54
     }
32 55
 
33 56
     @Override
34 57
     public Boolean has(IdentifiableInterface object) {
35
-        return null;
58
+        for (IdentifiableInterface id : list) {
59
+            if (list.contains(id)) return true;
60
+        }
61
+        return false;
36 62
     }
37 63
 
38 64
     @Override
39 65
     public Boolean has(Serializable serializable) {
40
-        return null;
66
+        Iterator iterator = list.iterator();
67
+        while (iterator.hasNext()){
68
+            IdentifiableInterface next = (IdentifiableInterface) iterator.next();
69
+            if(next.getIdentity().equals(serializable)) return true;
70
+        }
71
+        return false;
41 72
     }
42 73
 
43 74
     @Override
44 75
     public List filter(Predicate predicate) {
45
-        return null;
76
+        return (ArrayList<TypeOfEntity>)list.stream()
77
+                .filter(predicate)
78
+                .collect(Collectors.toList());
46 79
     }
47 80
 
48 81
     @Override
49 82
     public Class getIdentityType() {
50
-        return null;
83
+        return list.getClass();
51 84
     }
52 85
 
53 86
     @Override
54 87
     public Class getIdentifiableType() {
55
-        return null;
88
+        return this.getClass().getEnclosingClass();
56 89
     }
57 90
 
58 91
 }

+ 27
- 5
src/main/java/com/zipcodewilmington/generic/identifiables/ActionFigure.java Parādīt failu

@@ -5,14 +5,36 @@ 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
+    @Override
13
+    public TypeOfId getIdentity() {
14
+        return id;
15
+    }
9 16
 
10 17
     @Override
11
-    public Serializable getIdentity() {
12
-        return null;
18
+    public void setId(TypeOfId typeOfId) {
19
+        this.id = typeOfId;
13 20
     }
14 21
 
15
-    public Class getIdentityType() {
16
-        return null;
22
+    public Class<? extends Serializable> getIdentityType() {
23
+        return id.getClass();
17 24
     }
25
+
26
+//    @Override
27
+//    public void setId(Long aLong) {
28
+//
29
+//    }
30
+
31
+
32
+//    @Override
33
+//    public Serializable getIdentity() {
34
+//        return null;
35
+//    }
36
+//
37
+//    public Class getIdentityType() {
38
+//        return null;
39
+//    }
18 40
 }

+ 2
- 1
src/main/java/com/zipcodewilmington/generic/identifiables/IdentifiableInterface.java Parādīt failu

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

+ 23
- 5
src/main/java/com/zipcodewilmington/generic/identifiables/Person.java Parādīt failu

@@ -5,14 +5,32 @@ 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
+    }
9 14
 
10 15
     @Override
11
-    public Serializable getIdentity() {
12
-        return null;
16
+    public TypeOfId getIdentity() {
17
+        return id;
13 18
     }
14 19
 
15
-    public Class getIdentityType() {
16
-        return null;
20
+    public void setId(TypeOfId id) {
21
+        this.id = id;
17 22
     }
23
+
24
+    public Class<? extends Serializable> getIdentityType() {
25
+        return id.getClass();
26
+    }
27
+
28
+//    @Override
29
+//    public Serializable getIdentity() {
30
+//        return null;
31
+//    }
32
+//
33
+//    public Class getIdentityType() {
34
+//        return null;
35
+//    }
18 36
 }

+ 28
- 28
src/test/java/com/zipcodewilmington/generic/group/GetIdentityTypeTest.java Parādīt failu

@@ -1,28 +1,28 @@
1
-package com.zipcodewilmington.generic.group;
2
-
3
-import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
-import com.zipcodewilmington.generic.identifiables.Person;
5
-import org.junit.Assert;
6
-import org.junit.Test;
7
-
8
-/**
9
- * @author leon on 06/12/2018.
10
- * there is meaning to the madness
11
- * ( ͡☉ ͜ʖ ͡☉)
12
- */
13
-public class GetIdentityTypeTest {
14
-    private Group<String, Person> personGroup = new Group<>();
15
-    private Group<Long, ActionFigure> actionFigureGroup = new Group<>();
16
-
17
-    @Test
18
-    public void testGetIdentityType() { // ༼∵༽ ༼⍨༽ ༼⍢༽ ༼⍤༽
19
-        Assert.assertEquals(personGroup.getIdentityType(), String.class);
20
-        Assert.assertEquals(actionFigureGroup.getIdentityType(), Long.class);
21
-    }
22
-
23
-    @Test
24
-    public void testGetIdentifiableType() { // ヽ༼ ಠ益ಠ ༽ノ
25
-        Assert.assertEquals(personGroup.getIdentifiableType(), Person.class);
26
-        Assert.assertEquals(actionFigureGroup.getIdentifiableType(), ActionFigure.class);
27
-    }
28
-}
1
+//package com.zipcodewilmington.generic.group;
2
+//
3
+//import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+//import com.zipcodewilmington.generic.identifiables.Person;
5
+//import org.junit.Assert;
6
+//import org.junit.Test;
7
+//
8
+///**
9
+// * @author leon on 06/12/2018.
10
+// * there is meaning to the madness
11
+// * ( ͡☉ ͜ʖ ͡☉)
12
+// */
13
+//public class GetIdentityTypeTest {
14
+//    private Group<String, Person> personGroup = new Group<>();
15
+//    private Group<Long, ActionFigure> actionFigureGroup = new Group<>();
16
+//
17
+//    @Test
18
+//    public void testGetIdentityType() { // ༼∵༽ ༼⍨༽ ༼⍢༽ ༼⍤༽
19
+//        Assert.assertEquals(personGroup.getIdentityType(), String.class);
20
+//        Assert.assertEquals(actionFigureGroup.getIdentityType(), Long.class);
21
+//    }
22
+//
23
+//    @Test
24
+//    public void testGetIdentifiableType() { // ヽ༼ ಠ益ಠ ༽ノ
25
+//        Assert.assertEquals(personGroup.getIdentifiableType(), Person.class);
26
+//        Assert.assertEquals(actionFigureGroup.getIdentifiableType(), ActionFigure.class);
27
+//    }
28
+//}