Procházet zdrojové kódy

Debugging StreamFilter...stash

vvmk před 6 roky
rodič
revize
877cd4d189

+ 19
- 10
src/main/java/com/zipcodewilmington/streams/StreamFilter.java Zobrazit soubor

@@ -19,7 +19,7 @@ public class StreamFilter {
19 19
 
20 20
     /**
21 21
      * No arg constructor
22
-     */ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
22
+     */
23 23
     public StreamFilter() {
24 24
         this(PersonFactory.createPersonStream(100), RandomUtils.createCharacter('A', 'Z'));
25 25
     }
@@ -35,7 +35,7 @@ public class StreamFilter {
35 35
     /**
36 36
      * @param people - List of person objects
37 37
      * @param startingCharacter - character to filter by
38
-     */ //TODO
38
+     */
39 39
     public StreamFilter(List<Person> people, Character startingCharacter) {
40 40
         this(people.stream(), startingCharacter);
41 41
     }
@@ -54,36 +54,45 @@ public class StreamFilter {
54 54
     /**
55 55
      * Using multi-line lambda syntax
56 56
      * @return a list of person object whose name starts with `this.startingCharacter`
57
-     */ //TODO
57
+     */ // Is this what he means?
58 58
     public List<Person> toListMultiLine() {
59
-        return null;
59
+        return personStream.filter(p -> {
60
+           return p.getName().charAt(0) == startingCharacter.charAt(0);
61
+        }).collect(Collectors.toList());
60 62
     }
61 63
 
62 64
 
63 65
     /**
64 66
      * Using one-line lambda syntax
65 67
      * @return a list of person objects whose name starts with `this.startingCharacter`
66
-     */ //TODO
68
+     */
67 69
     public List<Person> toListOneLine() {
68
-        return null;
70
+        return personStream
71
+                .filter(p -> p.getName().charAt(0) == startingCharacter.charAt(0))
72
+                .collect(Collectors.toList());
69 73
     }
70 74
 
71 75
 
72 76
     /**
73 77
      * Using one-line lambda syntax
74 78
      * @return an array of person object whose name starts with `this.startingCharacter`
75
-     */ //TODO
79
+     */ //
76 80
     public Person[] toArrayOneLine() {
77
-        return null;
81
+        return personStream
82
+                .filter(p -> p.getName().charAt(0) == startingCharacter.charAt(0))
83
+                .toArray(Person[]::new);
78 84
     }
79 85
 
80 86
 
81 87
     /**
82 88
      * Using multi-line lambda syntax
83 89
      * @return an array of person object whose name starts with `this.startingCharacter`
84
-     */ //TODO
90
+     */ // again, not sure if this is what he means
85 91
     public Person[] toArrayMultiLine() {
86
-        return null;
92
+        return personStream
93
+                .filter(p -> {
94
+                    return p.getName().charAt(0) == startingCharacter.charAt(0);
95
+                }).toArray(Person[]::new);
87 96
     }
88 97
 
89 98
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/streams/tools/logging/LoggerHandler.java Zobrazit soubor

@@ -83,7 +83,7 @@ public final class LoggerHandler {
83 83
         FileHandler fh = null;
84 84
         try {
85 85
             removeHandlers(); // enables better printing control
86
-            String fileName = String.format("./target/%s.leonlog", loggerName, System.nanoTime());
86
+            String fileName = String.format("./target/%1s.%2s.leonlog", loggerName, System.nanoTime());
87 87
             fh = new FileHandler(fileName);
88 88
             fh.setFormatter(formatter);
89 89
         } catch (IOException ioe) {