Browse Source

Passed Most tests

Akeem Cherry 6 years ago
parent
commit
021ba77a63
23 changed files with 850946 additions and 963 deletions
  1. 2
    0
      .idea/compiler.xml
  2. 0
    13
      .idea/libraries/Maven__junit_junit_4_12.xml
  3. 13
    0
      .idea/libraries/Maven__junit_junit_4_13_beta_1.xml
  4. 491
    917
      .idea/workspace.xml
  5. 12
    0
      pom.xml
  6. 7
    7
      src/main/java/com/zipcodewilmington/streams/StreamFilter.java
  7. 3
    3
      src/main/java/com/zipcodewilmington/streams/StreamMap.java
  8. 6
    3
      src/main/java/com/zipcodewilmington/streams/anthropoid/PersonFactory.java
  9. 7
    5
      src/main/java/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.java
  10. 3
    2
      src/main/java/com/zipcodewilmington/streams/conversions/ArrayConverter.java
  11. 3
    2
      src/main/java/com/zipcodewilmington/streams/conversions/ListConverter.java
  12. 3
    3
      src/main/java/com/zipcodewilmington/streams/conversions/StreamConverter.java
  13. 1
    1
      streamdemo.iml
  14. 850394
    6
      target/PersonWarehouse.leonlog
  15. BIN
      target/classes/com/zipcodewilmington/streams/StreamFilter.class
  16. BIN
      target/classes/com/zipcodewilmington/streams/StreamMap.class
  17. BIN
      target/classes/com/zipcodewilmington/streams/anthropoid/PersonFactory.class
  18. BIN
      target/classes/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.class
  19. BIN
      target/classes/com/zipcodewilmington/streams/conversions/ArrayConverter.class
  20. BIN
      target/classes/com/zipcodewilmington/streams/conversions/ListConverter.class
  21. BIN
      target/classes/com/zipcodewilmington/streams/conversions/StreamConverter.class
  22. 1
    1
      target/global.leonlog
  23. BIN
      target/test-classes/com/zipcodewilmington/streams/TestStreamMap.class

+ 2
- 0
.idea/compiler.xml View File

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

+ 0
- 13
.idea/libraries/Maven__junit_junit_4_12.xml View File

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 View File

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>

+ 491
- 917
.idea/workspace.xml
File diff suppressed because it is too large
View File


+ 12
- 0
pom.xml View File

15
         </dependency>
15
         </dependency>
16
     </dependencies>
16
     </dependencies>
17
 
17
 
18
+    <build>
19
+        <plugins>
20
+            <plugin>
21
+                <groupId>org.apache.maven.plugins</groupId>
22
+                <artifactId>maven-compiler-plugin</artifactId>
23
+                <configuration>
24
+                    <source>1.8</source>
25
+                    <target>1.8</target>
26
+                </configuration>
27
+            </plugin>
28
+        </plugins>
29
+    </build>
18
 
30
 
19
 </project>
31
 </project>

+ 7
- 7
src/main/java/com/zipcodewilmington/streams/StreamFilter.java View File

20
      * No arg constructor
20
      * No arg constructor
21
      */ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
21
      */ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
22
     public StreamFilter() {
22
     public StreamFilter() {
23
-        this(Stream.empty(), null);
23
+        this(PersonFactory.createPersonStream(100), RandomUtils.createCharacter('A','Z'));
24
     }
24
     }
25
 
25
 
26
     /**
26
     /**
28
      * @param startingCharacter - character to filter by
28
      * @param startingCharacter - character to filter by
29
      */ //TODO
29
      */ //TODO
30
     public StreamFilter(Person[] people, Character startingCharacter) {
30
     public StreamFilter(Person[] people, Character startingCharacter) {
31
-        this(Stream.empty(), null);
31
+        this(Stream.of(people), startingCharacter);
32
     }
32
     }
33
 
33
 
34
     /**
34
     /**
36
      * @param startingCharacter - character to filter by
36
      * @param startingCharacter - character to filter by
37
      */ //TODO
37
      */ //TODO
38
     public StreamFilter(List<Person> people, Character startingCharacter) {
38
     public StreamFilter(List<Person> people, Character startingCharacter) {
39
-        this(Stream.empty(), null);
39
+        this(people.stream(), startingCharacter);
40
     }
40
     }
41
 
41
 
42
 
42
 
55
      * @return a list of person object whose name starts with `this.startingCharacter`
55
      * @return a list of person object whose name starts with `this.startingCharacter`
56
      */ //TODO
56
      */ //TODO
57
     public List<Person> toListMultiLine() {
57
     public List<Person> toListMultiLine() {
58
-        return null;
58
+        return personStream.filter(x -> x.getName().equalsIgnoreCase(startingCharacter)).collect(Collectors.toList());
59
     }
59
     }
60
 
60
 
61
 
61
 
64
      * @return a list of person objects whose name starts with `this.startingCharacter`
64
      * @return a list of person objects whose name starts with `this.startingCharacter`
65
      */ //TODO
65
      */ //TODO
66
     public List<Person> toListOneLine() {
66
     public List<Person> toListOneLine() {
67
-        return null;
67
+        return personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person.name)).collect(Collectors.toList());
68
     }
68
     }
69
 
69
 
70
 
70
 
73
      * @return an array of person object whose name starts with `this.startingCharacter`
73
      * @return an array of person object whose name starts with `this.startingCharacter`
74
      */ //TODO
74
      */ //TODO
75
     public Person[] toArrayOneLine() {
75
     public Person[] toArrayOneLine() {
76
-        return null;
76
+        return personStream.filter(x -> x.getName().equalsIgnoreCase(startingCharacter)).toArray(Person[]::new);
77
     }
77
     }
78
 
78
 
79
 
79
 
82
      * @return an array of person object whose name starts with `this.startingCharacter`
82
      * @return an array of person object whose name starts with `this.startingCharacter`
83
      */ //TODO
83
      */ //TODO
84
     public Person[] toArrayMultiLine() {
84
     public Person[] toArrayMultiLine() {
85
-        return null;
85
+        return personStream.filter(x -> x.getName().equalsIgnoreCase(startingCharacter)).toArray(Person[]::new);
86
     }
86
     }
87
 
87
 
88
 }
88
 }

+ 3
- 3
src/main/java/com/zipcodewilmington/streams/StreamMap.java View File

18
      * @return - a Stream of single characters
18
      * @return - a Stream of single characters
19
      */ //TODO
19
      */ //TODO
20
     public static Stream<String> letters(String someWord) {
20
     public static Stream<String> letters(String someWord) {
21
-        return null;
21
+        return Stream.of(someWord);
22
     }
22
     }
23
 
23
 
24
     /**
24
     /**
26
      * @return - a Stream of several Streams of single characters
26
      * @return - a Stream of several Streams of single characters
27
      */ //TODO
27
      */ //TODO
28
     public static Stream<Stream<String>> wordsMap(String... someWords) {
28
     public static Stream<Stream<String>> wordsMap(String... someWords) {
29
-        return null;
29
+        return Stream.of(someWords).map(x -> letters(x));
30
     }
30
     }
31
 
31
 
32
     /**
32
     /**
34
      * @return - a Stream of several Streams of single characters
34
      * @return - a Stream of several Streams of single characters
35
      */ //TODO
35
      */ //TODO
36
     public static Stream<String> wordsFlatMap(String... stringArray) {
36
     public static Stream<String> wordsFlatMap(String... stringArray) {
37
-        return null;
37
+        return Stream.of(stringArray).flatMap(x -> letters(x));
38
     }
38
     }
39
 }
39
 }

+ 6
- 3
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonFactory.java View File

3
 import com.zipcodewilmington.streams.tools.RandomUtils;
3
 import com.zipcodewilmington.streams.tools.RandomUtils;
4
 import com.zipcodewilmington.streams.tools.StringUtils;
4
 import com.zipcodewilmington.streams.tools.StringUtils;
5
 
5
 
6
+import java.util.ArrayList;
6
 import java.util.Date;
7
 import java.util.Date;
7
 import java.util.List;
8
 import java.util.List;
8
 import java.util.stream.Collectors;
9
 import java.util.stream.Collectors;
39
      * @return - ArrayList of Person objects
40
      * @return - ArrayList of Person objects
40
      */ // TODO
41
      */ // TODO
41
     public static List<Person> createPersonList(int listSize) {
42
     public static List<Person> createPersonList(int listSize) {
42
-        return null;
43
+
44
+        return Stream.generate(PersonFactory::createRandomPerson).limit(listSize).collect(Collectors.toList());
43
     }
45
     }
44
 
46
 
45
 
47
 
48
      * @return - Array of Person objects
50
      * @return - Array of Person objects
49
      */ // TODO
51
      */ // TODO
50
     public static Person[] createPersonArray(int arrayLength) {
52
     public static Person[] createPersonArray(int arrayLength) {
51
-        return null;
53
+
54
+        return Stream.generate(PersonFactory::createRandomPerson).limit(arrayLength).toArray(Person[]::new);
52
     }
55
     }
53
 
56
 
54
 
57
 
58
      * @return - Stream representation of collection of Person objects
61
      * @return - Stream representation of collection of Person objects
59
      */ // TODO
62
      */ // TODO
60
     public static Stream<Person> createPersonStream(int streamCount) {
63
     public static Stream<Person> createPersonStream(int streamCount) {
61
-        return null;
64
+        return Stream.generate(PersonFactory::createRandomPerson).limit(streamCount);
62
     }
65
     }
63
 }
66
 }

+ 7
- 5
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.java View File

35
      * @return list of uniquely named Person objects
35
      * @return list of uniquely named Person objects
36
      */ //TODO
36
      */ //TODO
37
     public static Stream<Person> getUniquelyNamedPeople() {
37
     public static Stream<Person> getUniquelyNamedPeople() {
38
-        return null;
38
+        return people.stream().distinct();
39
     }
39
     }
40
 
40
 
41
 
41
 
44
      * @return a Stream of respective
44
      * @return a Stream of respective
45
      */ //TODO
45
      */ //TODO
46
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
46
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
47
-        return null;
47
+        return people.stream().filter(x -> x.getName().startsWith(character.toString()));
48
     }
48
     }
49
 
49
 
50
     /**
50
     /**
52
      * @return a Stream of respective
52
      * @return a Stream of respective
53
      */ //TODO
53
      */ //TODO
54
     public static Stream<Person> getFirstNUniquelyNamedPeople(int n) {
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
      * @return a mapping of Person Id to the respective Person name
60
      * @return a mapping of Person Id to the respective Person name
60
      */ // TODO
61
      */ // TODO
61
     public static Map<Long, String> getIdToNameMap() {
62
     public static Map<Long, String> getIdToNameMap() {
62
-        return null;
63
+
64
+        return people.stream().collect(Collectors.toMap(Person::getPersonalId, Person::getName));
63
     }
65
     }
64
 
66
 
65
 
67
 
82
      * @return list of names of Person objects
84
      * @return list of names of Person objects
83
      */ // TODO
85
      */ // TODO
84
     public static List<String> getNames() {
86
     public static List<String> getNames() {
85
-        return null;
87
+        return people.stream().map(x -> x.getName()).collect(Collectors.toList());
86
     }
88
     }
87
 
89
 
88
     /**
90
     /**

+ 3
- 2
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
 /**
23
 
24
 
24
     //TODO
25
     //TODO
25
     public List<Person> toList() {
26
     public List<Person> toList() {
26
-        return null;
27
+        return Arrays.stream(super.objectSequence).collect(Collectors.toList());
27
     }
28
     }
28
 
29
 
29
     //TODO
30
     //TODO
30
     public Stream<Person> toStream() {
31
     public Stream<Person> toStream() {
31
-        return null;
32
+        return Arrays.stream(super.objectSequence);
32
     }
33
     }
33
 
34
 
34
     @Override
35
     @Override

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

27
 
27
 
28
     //TODO
28
     //TODO
29
     public Stream<Person> toStream() {
29
     public Stream<Person> toStream() {
30
-        return null;
30
+
31
+        return super.objectSequence.stream();
31
     }
32
     }
32
 
33
 
33
     //TODO
34
     //TODO
34
     public Person[] toArray() {
35
     public Person[] toArray() {
35
-        return null;
36
+        return super.objectSequence.stream().toArray(Person[]::new);
36
     }
37
     }
37
 }
38
 }

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

25
 
25
 
26
     // TODO
26
     // TODO
27
     public List<Person> toList() {
27
     public List<Person> toList() {
28
-        return null;
28
+        return personList;
29
     }
29
     }
30
 
30
 
31
     // TODO
31
     // TODO
32
     public Stream<Person> toStream() {
32
     public Stream<Person> toStream() {
33
-        return null;
33
+        return personList.stream();
34
     }
34
     }
35
 
35
 
36
     // TODO
36
     // TODO
37
     public Person[] toArray() {
37
     public Person[] toArray() {
38
-        return null;
38
+        return personList.stream().toArray(Person[]::new);
39
     }
39
     }
40
 }
40
 }

+ 1
- 1
streamdemo.iml View File

11
     </content>
11
     </content>
12
     <orderEntry type="inheritedJdk" />
12
     <orderEntry type="inheritedJdk" />
13
     <orderEntry type="sourceFolder" forTests="false" />
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
     <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
     <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
16
   </component>
16
   </component>
17
 </module>
17
 </module>

+ 850394
- 6
target/PersonWarehouse.leonlog
File diff suppressed because it is too large
View File


BIN
target/classes/com/zipcodewilmington/streams/StreamFilter.class View File


BIN
target/classes/com/zipcodewilmington/streams/StreamMap.class View File


BIN
target/classes/com/zipcodewilmington/streams/anthropoid/PersonFactory.class View File


BIN
target/classes/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.class View File


BIN
target/classes/com/zipcodewilmington/streams/conversions/ArrayConverter.class View File


BIN
target/classes/com/zipcodewilmington/streams/conversions/ListConverter.class View File


BIN
target/classes/com/zipcodewilmington/streams/conversions/StreamConverter.class View File


+ 1
- 1
target/global.leonlog View File

1
-May 31, 2017 4:45:59 PM com.zipcodewilmington.streams.tools.logging.LoggerHandler log
1
+Nov 29, 2018 8:33:43 PM com.zipcodewilmington.streams.tools.logging.LoggerHandler log
2
 INFO: Instantiating logger for [ com.zipcodewilmington.streams.anthropoid.PersonWarehouse ] ... 
2
 INFO: Instantiating logger for [ com.zipcodewilmington.streams.anthropoid.PersonWarehouse ] ... 

BIN
target/test-classes/com/zipcodewilmington/streams/TestStreamMap.class View File