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
 
5
 
6
 import java.util.Arrays;
6
 import java.util.Arrays;
7
 import java.util.List;
7
 import java.util.List;
8
+import java.util.stream.Collectors;
8
 import java.util.stream.Stream;
9
 import java.util.stream.Stream;
9
 
10
 
10
 /**
11
 /**
21
          *  @param collectionSize  - length of Array to be generated */
22
          *  @param collectionSize  - length of Array to be generated */
22
     }
23
     }
23
 
24
 
24
-    //TODO
25
     public List<Person> toList() {
25
     public List<Person> toList() {
26
-        return null;
26
+        return Arrays.stream(objectSequence).collect(Collectors.toList());
27
     }
27
     }
28
 
28
 
29
-    //TODO
30
     public Stream<Person> toStream() {
29
     public Stream<Person> toStream() {
31
-        return null;
30
+        return Stream.of(objectSequence);
32
     }
31
     }
33
 
32
 
34
     @Override
33
     @Override

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

25
         return super.objectSequence;
25
         return super.objectSequence;
26
     }
26
     }
27
 
27
 
28
-    //TODO
29
     public Stream<Person> toStream() {
28
     public Stream<Person> toStream() {
30
-        return null;
29
+        return super.objectSequence.stream();
31
     }
30
     }
32
 
31
 
33
-    //TODO
34
     public Person[] toArray() {
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
          *  @param collectionSize  - count of Stream to be generated */
23
          *  @param collectionSize  - count of Stream to be generated */
24
     }
24
     }
25
 
25
 
26
-    // TODO
27
     public List<Person> toList() {
26
     public List<Person> toList() {
28
-        return null;
27
+        return personList; // ?
29
     }
28
     }
30
 
29
 
31
-    // TODO
32
     public Stream<Person> toStream() {
30
     public Stream<Person> toStream() {
33
-        return null;
31
+        return personList.stream(); // ??
34
     }
32
     }
35
 
33
 
36
-    // TODO
37
     public Person[] toArray() {
34
     public Person[] toArray() {
38
-        return null;
35
+        return personList.toArray(new Person[0]);
39
     }
36
     }
40
 }
37
 }