#29 array converter done

Aberto
jacob-andersen quer mesclar 1 commits de jacob-andersen/CR-MicroLabs-Streams-And-Lambdas:master em master

+ 3
- 2
.idea/compiler.xml Ver arquivo

@@ -7,10 +7,11 @@
7 7
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8 8
         <outputRelativeToContentRoot value="true" />
9 9
         <module name="looptest" />
10
+        <module name="streamdemo" />
10 11
       </profile>
11 12
     </annotationProcessing>
12
-    <bytecodeTargetLevel target="1.8">
13
-      <module name="looptest" target="1.8" />
13
+    <bytecodeTargetLevel target="8">
14
+      <module name="streamdemo" target="8" />
14 15
     </bytecodeTargetLevel>
15 16
   </component>
16 17
 </project>

+ 4
- 0
.idea/encodings.xml Ver arquivo

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="Encoding" addBOMForNewFiles="with NO BOM" />
4
+</project>

+ 5
- 1
.idea/kotlinc.xml Ver arquivo

@@ -1,7 +1,11 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3
+  <component name="Kotlin2JsCompilerArguments">
4
+    <option name="sourceMapEmbedSources" />
5
+    <option name="sourceMapPrefix" />
6
+  </component>
3 7
   <component name="KotlinCommonCompilerArguments">
4
-    <option name="languageVersion" value="1.1" />
5 8
     <option name="apiVersion" value="1.1" />
9
+    <option name="languageVersion" value="1.1" />
6 10
   </component>
7 11
 </project>

+ 0
- 13
.idea/libraries/Maven__junit_junit_4_12.xml Ver arquivo

@@ -1,13 +0,0 @@
1
-<component name="libraryTable">
2
-  <library name="Maven: junit:junit:4.12">
3
-    <CLASSES>
4
-      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
5
-    </CLASSES>
6
-    <JAVADOC>
7
-      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
8
-    </JAVADOC>
9
-    <SOURCES>
10
-      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
11
-    </SOURCES>
12
-  </library>
13
-</component>

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_13_beta_1.xml Ver arquivo

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: junit:junit:4.13-beta-1">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13-beta-1/junit-4.13-beta-1.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13-beta-1/junit-4.13-beta-1-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13-beta-1/junit-4.13-beta-1-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 499
- 958
.idea/workspace.xml
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 12
- 0
pom.xml Ver arquivo

@@ -7,6 +7,18 @@
7 7
     <groupId>mygroupid</groupId>
8 8
     <artifactId>looptest</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
     <dependencies>
11 23
         <dependency>
12 24
             <groupId>junit</groupId>

+ 6
- 2
src/main/java/com/zipcodewilmington/streams/StreamMap.java Ver arquivo

@@ -6,6 +6,7 @@ import com.zipcodewilmington.streams.conversions.StreamConverter;
6 6
 import java.util.Arrays;
7 7
 import java.util.List;
8 8
 import java.util.stream.Collectors;
9
+import java.util.stream.IntStream;
9 10
 import java.util.stream.Stream;
10 11
 
11 12
 /**
@@ -17,8 +18,11 @@ public class StreamMap {
17 18
      * @param someWord - word to convert to Stream<String>
18 19
      * @return - a Stream of single characters
19 20
      */ //TODO
20
-    public static Stream<String> letters(String someWord) {
21
-        return null;
21
+    public static Stream<String> letters(String someWord)
22
+    {
23
+        Stream<String> stringstream = someWord.chars()
24
+                .mapToObj(c -> String.valueOf((char)c));
25
+        return stringstream;
22 26
     }
23 27
 
24 28
     /**

+ 11
- 4
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonFactory.java Ver arquivo

@@ -38,8 +38,11 @@ public final class PersonFactory {
38 38
      * @param listSize - number of Person objects to create
39 39
      * @return - ArrayList of Person objects
40 40
      */ // TODO
41
-    public static List<Person> createPersonList(int listSize) {
42
-        return null;
41
+    public static List<Person> createPersonList(int listSize)
42
+    {
43
+        return Stream.generate(PersonFactory::createRandomPerson)
44
+                .limit(listSize)
45
+                .collect(Collectors.toList());
43 46
     }
44 47
 
45 48
 
@@ -48,7 +51,9 @@ public final class PersonFactory {
48 51
      * @return - Array of Person objects
49 52
      */ // TODO
50 53
     public static Person[] createPersonArray(int arrayLength) {
51
-        return null;
54
+        return Stream.generate(PersonFactory::createRandomPerson)
55
+                .limit(arrayLength)
56
+                .toArray(Person[]::new);
52 57
     }
53 58
 
54 59
 
@@ -58,6 +63,8 @@ public final class PersonFactory {
58 63
      * @return - Stream representation of collection of Person objects
59 64
      */ // TODO
60 65
     public static Stream<Person> createPersonStream(int streamCount) {
61
-        return null;
66
+
67
+        return Stream.generate(PersonFactory::createRandomPerson)
68
+                .limit(streamCount);
62 69
     }
63 70
 }

+ 23
- 11
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.java Ver arquivo

@@ -5,6 +5,7 @@ import com.zipcodewilmington.streams.tools.logging.LoggerHandler;
5 5
 import com.zipcodewilmington.streams.tools.logging.LoggerWarehouse;
6 6
 
7 7
 import java.util.ArrayList;
8
+import java.util.Arrays;
8 9
 import java.util.List;
9 10
 import java.util.Map;
10 11
 import java.util.stream.Collectors;
@@ -35,7 +36,9 @@ public final class PersonWarehouse {
35 36
      * @return list of uniquely named Person objects
36 37
      */ //TODO
37 38
     public static Stream<Person> getUniquelyNamedPeople() {
38
-        return null;
39
+
40
+        return people.stream()
41
+                .distinct();
39 42
     }
40 43
 
41 44
 
@@ -44,29 +47,35 @@ public final class PersonWarehouse {
44 47
      * @return a Stream of respective
45 48
      */ //TODO
46 49
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
47
-        return null;
50
+        return getUniquelyNamedPeople().filter(person -> person.getName()
51
+                .startsWith(character.toString()));
48 52
     }
49 53
 
50 54
     /**
51 55
      * @param n first `n` Person objects
52 56
      * @return a Stream of respective
53 57
      */ //TODO
54
-    public static Stream<Person> getFirstNUniquelyNamedPeople(int n) {
55
-        return null;
58
+    public static Stream<Person> getFirstNUniquelyNamedPeople(int n)
59
+    {
60
+        return people.stream()
61
+        .distinct()
62
+        .limit(n);
56 63
     }
57 64
 
58 65
     /**
59 66
      * @return a mapping of Person Id to the respective Person name
60 67
      */ // TODO
61
-    public static Map<Long, String> getIdToNameMap() {
62
-        return null;
68
+    public static Map<Long, String> getIdToNameMap()
69
+    {
70
+        return people.stream().collect(Collectors.toMap(Person::getPersonalId,Person::getName));
63 71
     }
64 72
 
65 73
 
66 74
     /**
67 75
      * @return Stream of Stream of Aliases
68 76
      */ // TODO
69
-    public static Stream<Stream<String>> getNestedAliases() {
77
+    public static Stream<Stream<String>> getNestedAliases()
78
+    {
70 79
         return null;
71 80
     }
72 81
 
@@ -74,22 +83,25 @@ public final class PersonWarehouse {
74 83
     /**
75 84
      * @return Stream of all Aliases
76 85
      */ // TODO
77
-    public static Stream<String> getAllAliases() {
86
+    public static Stream<String> getAllAliases()
87
+    {
78 88
         return null;
89
+
79 90
     }
80 91
 
81 92
     /**
82 93
      * @return list of names of Person objects
83 94
      */ // TODO
84 95
     public static List<String> getNames() {
85
-        return null;
96
+        return people.stream().map(Person::getName).collect(Collectors.toList());
86 97
     }
87 98
 
88 99
     /**
89 100
      * @return ArrayList of all Person objects in this warehouse
90 101
      */
91
-    public static ArrayList<Person> getPeople() {
92
-        return people;
102
+    public static ArrayList<Person> getPeople()
103
+    {
104
+        return people.stream().collect(Collectors.toCollection(ArrayList::new));
93 105
     }
94 106
 
95 107
 }

+ 10
- 5
src/main/java/com/zipcodewilmington/streams/conversions/ArrayConverter.java Ver arquivo

@@ -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
 /**
@@ -22,17 +23,21 @@ public final class ArrayConverter extends PersonConversionAgent<Person[]> {
22 23
     }
23 24
 
24 25
     //TODO
25
-    public List<Person> toList() {
26
-        return null;
26
+    public List<Person> toList()
27
+    {
28
+        return Stream.of(objectSequence).collect(Collectors.toList());
29
+
27 30
     }
28 31
 
29 32
     //TODO
30
-    public Stream<Person> toStream() {
31
-        return null;
33
+    public Stream<Person> toStream()
34
+    {
35
+        return Stream.of(objectSequence);
32 36
     }
33 37
 
34 38
     @Override
35
-    public Person[] toArray() {
39
+    public Person[] toArray()
40
+    {
36 41
         return super.objectSequence;
37 42
     }
38 43
 }

+ 3
- 1
src/main/java/com/zipcodewilmington/streams/conversions/ListConverter.java Ver arquivo

@@ -4,6 +4,7 @@ import com.zipcodewilmington.streams.anthropoid.Person;
4 4
 import com.zipcodewilmington.streams.anthropoid.PersonFactory;
5 5
 
6 6
 import java.util.List;
7
+import java.util.stream.Collectors;
7 8
 import java.util.stream.Stream;
8 9
 
9 10
 /**
@@ -26,7 +27,8 @@ public final class ListConverter extends PersonConversionAgent<List<Person>> {
26 27
     }
27 28
 
28 29
     //TODO
29
-    public Stream<Person> toStream() {
30
+    public Stream<Person> toStream()
31
+    {
30 32
         return null;
31 33
     }
32 34
 

+ 1
- 1
streamdemo.iml Ver arquivo

@@ -11,7 +11,7 @@
11 11
     </content>
12 12
     <orderEntry type="inheritedJdk" />
13 13
     <orderEntry type="sourceFolder" forTests="false" />
14
-    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" name="Maven: junit:junit:4.13-beta-1" level="project" />
15 15
     <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
16 16
   </component>
17 17
 </module>

+ 111866
- 6
target/PersonWarehouse.leonlog
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


BIN
target/classes/com/zipcodewilmington/streams/StreamMap.class Ver arquivo


BIN
target/classes/com/zipcodewilmington/streams/anthropoid/PersonFactory.class Ver arquivo


BIN
target/classes/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.class Ver arquivo


BIN
target/classes/com/zipcodewilmington/streams/conversions/ArrayConverter.class Ver arquivo


BIN
target/classes/com/zipcodewilmington/streams/conversions/ListConverter.class Ver arquivo


+ 1
- 1
target/global.leonlog Ver arquivo

@@ -1,2 +1,2 @@
1
-May 31, 2017 4:45:59 PM com.zipcodewilmington.streams.tools.logging.LoggerHandler log
1
+Nov 26, 2018 7:59:57 PM com.zipcodewilmington.streams.tools.logging.LoggerHandler log
2 2
 INFO: Instantiating logger for [ com.zipcodewilmington.streams.anthropoid.PersonWarehouse ] ... 

BIN
target/test-classes/com/zipcodewilmington/streams/TestStreamMap.class Ver arquivo