De'Jon Johnson před 6 roky
rodič
revize
a04cc032d2

+ 2
- 0
.idea/compiler.xml Zobrazit soubor

@@ -7,10 +7,12 @@
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 13
     <bytecodeTargetLevel target="1.8">
13 14
       <module name="looptest" target="1.8" />
15
+      <module name="streamdemo" target="8" />
14 16
     </bytecodeTargetLevel>
15 17
   </component>
16 18
 </project>

+ 0
- 13
.idea/libraries/Maven__junit_junit_4_12.xml Zobrazit soubor

@@ -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 Zobrazit soubor

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

+ 457
- 853
.idea/workspace.xml
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 12
- 0
pom.xml Zobrazit soubor

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

+ 23
- 8
src/main/java/com/zipcodewilmington/streams/StreamFilter.java Zobrazit soubor

@@ -5,7 +5,9 @@ import com.zipcodewilmington.streams.anthropoid.PersonFactory;
5 5
 import com.zipcodewilmington.streams.tools.RandomUtils;
6 6
 import com.zipcodewilmington.streams.tools.StringUtils;
7 7
 
8
+import java.util.Arrays;
8 9
 import java.util.List;
10
+import java.util.function.Predicate;
9 11
 import java.util.stream.Collectors;
10 12
 import java.util.stream.Stream;
11 13
 
@@ -14,13 +16,15 @@ import java.util.stream.Stream;
14 16
  */
15 17
 public class StreamFilter {
16 18
     private final Stream<Person> personStream;
17
-    public final String startingCharacter;
19
+    private final String startingCharacter;
20
+
18 21
 
19 22
     /**
20 23
      * No arg constructor
21 24
      */ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
22 25
     public StreamFilter() {
23
-        this(Stream.empty(), null);
26
+
27
+        this(PersonFactory.createPersonStream(10), RandomUtils.createCharacter('A','Z'));
24 28
     }
25 29
 
26 30
     /**
@@ -28,7 +32,8 @@ public class StreamFilter {
28 32
      * @param startingCharacter - character to filter by
29 33
      */ //TODO
30 34
     public StreamFilter(Person[] people, Character startingCharacter) {
31
-        this(Stream.empty(), null);
35
+
36
+        this(Arrays.stream(people), startingCharacter);
32 37
     }
33 38
 
34 39
     /**
@@ -36,7 +41,7 @@ public class StreamFilter {
36 41
      * @param startingCharacter - character to filter by
37 42
      */ //TODO
38 43
     public StreamFilter(List<Person> people, Character startingCharacter) {
39
-        this(Stream.empty(), null);
44
+        this(people.stream(), startingCharacter);
40 45
     }
41 46
 
42 47
 
@@ -44,6 +49,7 @@ public class StreamFilter {
44 49
      * @param people - Stream of person objects
45 50
      * @param startingCharacter - character to filter by
46 51
      */ // I took care of the easy constructor (͡° ͜ʖ ͡°)
52
+
47 53
     public StreamFilter(Stream<Person> people, Character startingCharacter) {
48 54
         this.personStream = people;
49 55
         this.startingCharacter = startingCharacter.toString();
@@ -55,7 +61,12 @@ public class StreamFilter {
55 61
      * @return a list of person object whose name starts with `this.startingCharacter`
56 62
      */ //TODO
57 63
     public List<Person> toListMultiLine() {
58
-        return null;
64
+
65
+
66
+        Predicate<Person> filter = person -> StringUtils.isPalindromeIgnoreCase(person.getName());
67
+         return personStream
68
+             .filter(filter)
69
+             .collect(Collectors.toList());
59 70
     }
60 71
 
61 72
 
@@ -64,7 +75,7 @@ public class StreamFilter {
64 75
      * @return a list of person objects whose name starts with `this.startingCharacter`
65 76
      */ //TODO
66 77
     public List<Person> toListOneLine() {
67
-        return null;
78
+        return personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person.getName())).collect(Collectors.toList());
68 79
     }
69 80
 
70 81
 
@@ -73,7 +84,7 @@ public class StreamFilter {
73 84
      * @return an array of person object whose name starts with `this.startingCharacter`
74 85
      */ //TODO
75 86
     public Person[] toArrayOneLine() {
76
-        return null;
87
+        return personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person.getName())).toArray(Person[]::new);
77 88
     }
78 89
 
79 90
 
@@ -82,7 +93,11 @@ public class StreamFilter {
82 93
      * @return an array of person object whose name starts with `this.startingCharacter`
83 94
      */ //TODO
84 95
     public Person[] toArrayMultiLine() {
85
-        return null;
96
+        return personStream.filter(person -> {StringBuilder reverseName = new StringBuilder();
97
+          for (int i = person.getName().length() - 1; i > 0; i--) {
98
+               reverseName.append(person.getName().charAt(i));
99
+              } return reverseName.toString().equalsIgnoreCase(person.getName());
100
+         }).toArray(Person[]::new);
86 101
     }
87 102
 
88 103
 }

+ 4
- 3
src/main/java/com/zipcodewilmington/streams/StreamMap.java Zobrazit soubor

@@ -18,7 +18,8 @@ public class StreamMap {
18 18
      * @return - a Stream of single characters
19 19
      */ //TODO
20 20
     public static Stream<String> letters(String someWord) {
21
-        return null;
21
+        String[] characters = someWord.split("");
22
+        return Arrays.stream(characters);
22 23
     }
23 24
 
24 25
     /**
@@ -26,7 +27,7 @@ public class StreamMap {
26 27
      * @return - a Stream of several Streams of single characters
27 28
      */ //TODO
28 29
     public static Stream<Stream<String>> wordsMap(String... someWords) {
29
-        return null;
30
+        return Stream.of(someWords).map(word -> letters(word));
30 31
     }
31 32
 
32 33
     /**
@@ -34,6 +35,6 @@ public class StreamMap {
34 35
      * @return - a Stream of several Streams of single characters
35 36
      */ //TODO
36 37
     public static Stream<String> wordsFlatMap(String... stringArray) {
37
-        return null;
38
+        return Stream.of(stringArray).flatMap(word -> letters(word));
38 39
     }
39 40
 }

+ 5
- 3
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonFactory.java Zobrazit soubor

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

+ 5
- 4
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.java Zobrazit soubor

@@ -35,7 +35,7 @@ public final class PersonWarehouse {
35 35
      * @return list of uniquely named Person objects
36 36
      */ //TODO
37 37
     public static Stream<Person> getUniquelyNamedPeople() {
38
-        return null;
38
+        return people.stream().distinct();
39 39
     }
40 40
 
41 41
 
@@ -44,7 +44,7 @@ public final class PersonWarehouse {
44 44
      * @return a Stream of respective
45 45
      */ //TODO
46 46
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
47
-        return null;
47
+        return people.stream().distinct().filter(person -> person.getName().charAt(0) == character);
48 48
     }
49 49
 
50 50
     /**
@@ -52,14 +52,15 @@ public final class PersonWarehouse {
52 52
      * @return a Stream of respective
53 53
      */ //TODO
54 54
     public static Stream<Person> getFirstNUniquelyNamedPeople(int n) {
55
-        return null;
55
+
56
+        return people.stream().distinct().limit(n);
56 57
     }
57 58
 
58 59
     /**
59 60
      * @return a mapping of Person Id to the respective Person name
60 61
      */ // TODO
61 62
     public static Map<Long, String> getIdToNameMap() {
62
-        return null;
63
+        return people.stream().collect(Collectors.toMap(Person::getPersonalId, Person::getName));
63 64
     }
64 65
 
65 66
 

+ 4
- 2
src/main/java/com/zipcodewilmington/streams/conversions/ArrayConverter.java Zobrazit soubor

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

+ 4
- 2
src/main/java/com/zipcodewilmington/streams/conversions/ListConverter.java Zobrazit soubor

@@ -22,16 +22,18 @@ public final class ListConverter extends PersonConversionAgent<List<Person>> {
22 22
 
23 23
     @Override
24 24
     public List<Person> toList() {
25
+
25 26
         return super.objectSequence;
26 27
     }
27 28
 
28 29
     //TODO
29 30
     public Stream<Person> toStream() {
30
-        return null;
31
+
32
+        return super.objectSequence.stream();
31 33
     }
32 34
 
33 35
     //TODO
34 36
     public Person[] toArray() {
35
-        return null;
37
+        return super.objectSequence.stream().toArray(Person[]::new);
36 38
     }
37 39
 }

+ 5
- 3
src/main/java/com/zipcodewilmington/streams/conversions/StreamConverter.java Zobrazit soubor

@@ -25,16 +25,18 @@ public final class StreamConverter extends PersonConversionAgent<Stream<Person>>
25 25
 
26 26
     // TODO
27 27
     public List<Person> toList() {
28
-        return null;
28
+        return personList;
29 29
     }
30 30
 
31 31
     // TODO
32 32
     public Stream<Person> toStream() {
33
-        return null;
33
+
34
+        return personList.stream();
34 35
     }
35 36
 
36 37
     // TODO
37 38
     public Person[] toArray() {
38
-        return null;
39
+
40
+        return personList.stream().toArray(Person[]::new);
39 41
     }
40 42
 }

+ 1
- 1
streamdemo.iml Zobrazit soubor

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