Browse Source

Implement converter methods

vvmk 6 years ago
parent
commit
d53e1e5178

+ 3
- 4
src/main/java/com/zipcodewilmington/streams/conversions/ArrayConverter.java View File

@@ -5,6 +5,7 @@ import com.zipcodewilmington.streams.anthropoid.PersonFactory;
5 5
 
6 6
 import java.util.Arrays;
7 7
 import java.util.List;
8
+import java.util.stream.Collectors;
8 9
 import java.util.stream.Stream;
9 10
 
10 11
 /**
@@ -21,14 +22,12 @@ public final class ArrayConverter extends PersonConversionAgent<Person[]> {
21 22
          *  @param collectionSize  - length of Array to be generated */
22 23
     }
23 24
 
24
-    //TODO
25 25
     public List<Person> toList() {
26
-        return null;
26
+        return Arrays.stream(objectSequence).collect(Collectors.toList());
27 27
     }
28 28
 
29
-    //TODO
30 29
     public Stream<Person> toStream() {
31
-        return null;
30
+        return Stream.of(objectSequence);
32 31
     }
33 32
 
34 33
     @Override

+ 2
- 4
src/main/java/com/zipcodewilmington/streams/conversions/ListConverter.java View File

@@ -25,13 +25,11 @@ public final class ListConverter extends PersonConversionAgent<List<Person>> {
25 25
         return super.objectSequence;
26 26
     }
27 27
 
28
-    //TODO
29 28
     public Stream<Person> toStream() {
30
-        return null;
29
+        return super.objectSequence.stream();
31 30
     }
32 31
 
33
-    //TODO
34 32
     public Person[] toArray() {
35
-        return null;
33
+        return super.objectSequence.toArray(new Person[0]);
36 34
     }
37 35
 }

+ 3
- 6
src/main/java/com/zipcodewilmington/streams/conversions/StreamConverter.java View File

@@ -23,18 +23,15 @@ public final class StreamConverter extends PersonConversionAgent<Stream<Person>>
23 23
          *  @param collectionSize  - count of Stream to be generated */
24 24
     }
25 25
 
26
-    // TODO
27 26
     public List<Person> toList() {
28
-        return null;
27
+        return personList; // ?
29 28
     }
30 29
 
31
-    // TODO
32 30
     public Stream<Person> toStream() {
33
-        return null;
31
+        return personList.stream(); // ??
34 32
     }
35 33
 
36
-    // TODO
37 34
     public Person[] toArray() {
38
-        return null;
35
+        return personList.toArray(new Person[0]);
39 36
     }
40 37
 }