Преглед на файлове

finished lab but one test won't pass

Eric Foster преди 6 години
родител
ревизия
b214ecc43f

+ 2
- 1
.idea/compiler.xml Целия файл

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>

+ 405
- 847
.idea/workspace.xml
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 12
- 0
pom.xml Целия файл

7
     <groupId>mygroupid</groupId>
7
     <groupId>mygroupid</groupId>
8
     <artifactId>looptest</artifactId>
8
     <artifactId>looptest</artifactId>
9
     <version>1.0-SNAPSHOT</version>
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
     <dependencies>
22
     <dependencies>
11
         <dependency>
23
         <dependency>
12
             <groupId>junit</groupId>
24
             <groupId>junit</groupId>

+ 14
- 7
src/main/java/com/zipcodewilmington/streams/StreamFilter.java Целия файл

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

+ 3
- 3
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonFactory.java Целия файл

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

+ 4
- 4
src/main/java/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.java Целия файл

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(p -> p.getName().matches("^"+character));
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
+        return getUniquelyNamedPeople().limit(n);
56
     }
56
     }
57
 
57
 
58
     /**
58
     /**
82
      * @return list of names of Person objects
82
      * @return list of names of Person objects
83
      */ // TODO
83
      */ // TODO
84
     public static List<String> getNames() {
84
     public static List<String> getNames() {
85
-        return null;
85
+        return people.stream().map(p -> p.getName()).collect(Collectors.toList());
86
     }
86
     }
87
 
87
 
88
     /**
88
     /**

+ 3
- 2
src/main/java/com/zipcodewilmington/streams/conversions/ArrayConverter.java Целия файл

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(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(objectSequence);
32
     }
33
     }
33
 
34
 
34
     @Override
35
     @Override

+ 4
- 3
src/main/java/com/zipcodewilmington/streams/conversions/ListConverter.java Целия файл

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

+ 3
- 3
src/main/java/com/zipcodewilmington/streams/conversions/StreamConverter.java Целия файл

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
 }

+ 850394
- 6
target/PersonWarehouse.leonlog
Файловите разлики са ограничени, защото са твърде много
Целия файл


BIN
target/classes/com/zipcodewilmington/streams/StreamFilter.class Целия файл


BIN
target/classes/com/zipcodewilmington/streams/anthropoid/PersonFactory.class Целия файл


BIN
target/classes/com/zipcodewilmington/streams/anthropoid/PersonWarehouse.class Целия файл


BIN
target/classes/com/zipcodewilmington/streams/conversions/ArrayConverter.class Целия файл


BIN
target/classes/com/zipcodewilmington/streams/conversions/ListConverter.class Целия файл


BIN
target/classes/com/zipcodewilmington/streams/conversions/StreamConverter.class Целия файл


+ 1
- 1
target/global.leonlog Целия файл

1
-May 31, 2017 4:45:59 PM com.zipcodewilmington.streams.tools.logging.LoggerHandler log
1
+Jun 29, 2018 8:34:53 AM 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 Целия файл