Browse Source

all tests pass except one for a class we're not allowed to edit :P

Allison Ziegler 6 years ago
parent
commit
07c4fc3b93

+ 2
- 1
.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="streamdemo" target="8" />
14
     </bytecodeTargetLevel>
15
     </bytecodeTargetLevel>
15
   </component>
16
   </component>
16
 </project>
17
 </project>

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


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

5
 import com.zipcodewilmington.streams.tools.RandomUtils;
5
 import com.zipcodewilmington.streams.tools.RandomUtils;
6
 import com.zipcodewilmington.streams.tools.StringUtils;
6
 import com.zipcodewilmington.streams.tools.StringUtils;
7
 
7
 
8
+import java.util.ArrayList;
9
+import java.util.Arrays;
8
 import java.util.List;
10
 import java.util.List;
11
+import java.util.function.Predicate;
9
 import java.util.stream.Collectors;
12
 import java.util.stream.Collectors;
10
 import java.util.stream.Stream;
13
 import java.util.stream.Stream;
11
 
14
 
20
      * No arg constructor
23
      * No arg constructor
21
      */ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
24
      */ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
22
     public StreamFilter() {
25
     public StreamFilter() {
23
-        this(Stream.empty(), null);
26
+        //this(Stream.empty(), null);
27
+        personStream = PersonFactory.createPersonStream(100);
28
+        startingCharacter = String.valueOf((char) 'A' + (Math.random()) * 26);
24
     }
29
     }
25
 
30
 
26
     /**
31
     /**
28
      * @param startingCharacter - character to filter by
33
      * @param startingCharacter - character to filter by
29
      */ //TODO
34
      */ //TODO
30
     public StreamFilter(Person[] people, Character startingCharacter) {
35
     public StreamFilter(Person[] people, Character startingCharacter) {
31
-        this(Stream.empty(), null);
36
+        personStream = Arrays.stream(people);
37
+        this.startingCharacter = String.valueOf(startingCharacter);
32
     }
38
     }
33
 
39
 
34
     /**
40
     /**
36
      * @param startingCharacter - character to filter by
42
      * @param startingCharacter - character to filter by
37
      */ //TODO
43
      */ //TODO
38
     public StreamFilter(List<Person> people, Character startingCharacter) {
44
     public StreamFilter(List<Person> people, Character startingCharacter) {
39
-        this(Stream.empty(), null);
45
+        personStream = people.stream();
46
+        this.startingCharacter = String.valueOf(startingCharacter);
40
     }
47
     }
41
 
48
 
42
 
49
 
55
      * @return a list of person object whose name starts with `this.startingCharacter`
62
      * @return a list of person object whose name starts with `this.startingCharacter`
56
      */ //TODO
63
      */ //TODO
57
     public List<Person> toListMultiLine() {
64
     public List<Person> toListMultiLine() {
58
-        return null;
65
+        Predicate<Person> startsWithChar = person -> person.getName().matches("^" + this.startingCharacter);
66
+        return personStream.filter(startsWithChar).collect(Collectors.toList());
59
     }
67
     }
60
 
68
 
61
 
69
 
64
      * @return a list of person objects whose name starts with `this.startingCharacter`
72
      * @return a list of person objects whose name starts with `this.startingCharacter`
65
      */ //TODO
73
      */ //TODO
66
     public List<Person> toListOneLine() {
74
     public List<Person> toListOneLine() {
67
-        return null;
75
+        return personStream.filter(person -> person.getName().matches("^" + this.startingCharacter)).collect(Collectors.toList());
68
     }
76
     }
69
 
77
 
70
 
78
 
73
      * @return an array of person object whose name starts with `this.startingCharacter`
81
      * @return an array of person object whose name starts with `this.startingCharacter`
74
      */ //TODO
82
      */ //TODO
75
     public Person[] toArrayOneLine() {
83
     public Person[] toArrayOneLine() {
76
-        return null;
84
+        return personStream.filter(person -> person.getName().matches("^" + this.startingCharacter)).toArray(Person[]::new);
77
     }
85
     }
78
 
86
 
79
 
87
 
82
      * @return an array of person object whose name starts with `this.startingCharacter`
90
      * @return an array of person object whose name starts with `this.startingCharacter`
83
      */ //TODO
91
      */ //TODO
84
     public Person[] toArrayMultiLine() {
92
     public Person[] toArrayMultiLine() {
85
-        return null;
93
+        Predicate<Person> startsWithChar = person -> person.getName().matches("^" + this.startingCharacter);
94
+        return personStream.filter(startsWithChar).toArray(Person[]::new);
86
     }
95
     }
87
 
96
 
88
 }
97
 }

+ 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 Arrays.stream(someWord.split(""));
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 Arrays.stream(someWords).map(StreamMap::letters);
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 Arrays.stream(stringArray).flatMap(StreamMap::letters);
38
     }
38
     }
39
 }
39
 }

+ 4
- 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
+        return createPersonStream(listSize).collect(Collectors.toList());
43
     }
44
     }
44
 
45
 
45
 
46
 
48
      * @return - Array of Person objects
49
      * @return - Array of Person objects
49
      */ // TODO
50
      */ // TODO
50
     public static Person[] createPersonArray(int arrayLength) {
51
     public static Person[] createPersonArray(int arrayLength) {
51
-        return null;
52
+        return createPersonList(arrayLength).toArray(new Person[arrayLength]);
52
     }
53
     }
53
 
54
 
54
 
55
 
58
      * @return - Stream representation of collection of Person objects
59
      * @return - Stream representation of collection of Person objects
59
      */ // TODO
60
      */ // TODO
60
     public static Stream<Person> createPersonStream(int streamCount) {
61
     public static Stream<Person> createPersonStream(int streamCount) {
61
-        return null;
62
+        return Stream.generate(() -> createRandomPerson()).limit(streamCount);
62
     }
63
     }
63
 }
64
 }

+ 5
- 4
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
 
42
+
42
     /**
43
     /**
43
      * @param character starting character of Person objects' name
44
      * @param character starting character of Person objects' name
44
      * @return a Stream of respective
45
      * @return a Stream of respective
45
      */ //TODO
46
      */ //TODO
46
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
47
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
47
-        return null;
48
+        return getUniquelyNamedPeople().filter(person -> person.getName().matches("^"+character));
48
     }
49
     }
49
 
50
 
50
     /**
51
     /**
52
      * @return a Stream of respective
53
      * @return a Stream of respective
53
      */ //TODO
54
      */ //TODO
54
     public static Stream<Person> getFirstNUniquelyNamedPeople(int n) {
55
     public static Stream<Person> getFirstNUniquelyNamedPeople(int n) {
55
-        return null;
56
+        return getUniquelyNamedPeople().limit(n);
56
     }
57
     }
57
 
58
 
58
     /**
59
     /**
82
      * @return list of names of Person objects
83
      * @return list of names of Person objects
83
      */ // TODO
84
      */ // TODO
84
     public static List<String> getNames() {
85
     public static List<String> getNames() {
85
-        return null;
86
+        return people.stream().map(person -> person.getName()).collect(Collectors.toList());
86
     }
87
     }
87
 
88
 
88
     /**
89
     /**

+ 5
- 2
src/main/java/com/zipcodewilmington/streams/conversions/ArrayConverter.java View File

3
 import com.zipcodewilmington.streams.anthropoid.Person;
3
 import com.zipcodewilmington.streams.anthropoid.Person;
4
 import com.zipcodewilmington.streams.anthropoid.PersonFactory;
4
 import com.zipcodewilmington.streams.anthropoid.PersonFactory;
5
 
5
 
6
+import java.util.ArrayList;
6
 import java.util.Arrays;
7
 import java.util.Arrays;
7
 import java.util.List;
8
 import java.util.List;
9
+import java.util.stream.Collectors;
8
 import java.util.stream.Stream;
10
 import java.util.stream.Stream;
9
 
11
 
10
 /**
12
 /**
23
 
25
 
24
     //TODO
26
     //TODO
25
     public List<Person> toList() {
27
     public List<Person> toList() {
26
-        return null;
28
+
29
+        return Arrays.asList(objectSequence);
27
     }
30
     }
28
 
31
 
29
     //TODO
32
     //TODO
30
     public Stream<Person> toStream() {
33
     public Stream<Person> toStream() {
31
-        return null;
34
+        return Arrays.stream(objectSequence);
32
     }
35
     }
33
 
36
 
34
     @Override
37
     @Override

+ 2
- 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
+        return objectSequence.stream();
31
     }
31
     }
32
 
32
 
33
     //TODO
33
     //TODO
34
     public Person[] toArray() {
34
     public Person[] toArray() {
35
-        return null;
35
+        return objectSequence.toArray(new Person[objectSequence.size()]);
36
     }
36
     }
37
 }
37
 }

+ 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.stream().collect(Collectors.toList());
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
 }

+ 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
+Jun 28, 2018 5:09:36 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