Browse Source

all tests pass

katherine 7 years ago
parent
commit
6d2b71d36c

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

39
      * @return - ArrayList of Person objects
39
      * @return - ArrayList of Person objects
40
      */
40
      */
41
     public static List<Person> createPersonList(int listSize) {
41
     public static List<Person> createPersonList(int listSize) {
42
-        return Stream.generate(PersonFactory::createRandomPerson).limit(listSize).collect(Collectors.toList());
42
+        return createPersonStream(listSize).collect(Collectors.toList());
43
     }
43
     }
44
 
44
 
45
 
45
 

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

54
      */
54
      */
55
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
55
     public static Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
56
         String startsWithChar = Character.toString(character);
56
         String startsWithChar = Character.toString(character);
57
-        return people.stream().distinct().filter(p -> (p.getName().startsWith(startsWithChar)));
57
+        return getUniquelyNamedPeople().filter(p -> (p.getName().startsWith(startsWithChar)));
58
     }
58
     }
59
 
59
 
60
     /**
60
     /**

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

23
 
23
 
24
     //TODO
24
     //TODO
25
     public List<Person> toList() {
25
     public List<Person> toList() {
26
-        return null;
26
+        return Arrays.asList(this.toArray());
27
     }
27
     }
28
 
28
 
29
     //TODO
29
     //TODO
30
     public Stream<Person> toStream() {
30
     public Stream<Person> toStream() {
31
-        return null;
31
+        return this.toList().stream();
32
     }
32
     }
33
 
33
 
34
     @Override
34
     @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 this.toList().stream();
31
     }
31
     }
32
 
32
 
33
     //TODO
33
     //TODO
34
     public Person[] toArray() {
34
     public Person[] toArray() {
35
-        return null;
35
+        return this.toStream().toArray(Person[]::new);
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;
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 this.toStream().toArray(Person[]::new);
39
     }
39
     }
40
 }
40
 }

+ 5
- 2
src/test/java/com/zipcodewilmington/streams/TestStreamFilter.java View File

48
     }
48
     }
49
 
49
 
50
     private void testFilter(List<Person> persons) {
50
     private void testFilter(List<Person> persons) {
51
+        Person firstPerson = persons.get(0);
52
+        String startingCharacter = firstPerson.getName().substring(0,1);
51
         for (Person p : persons) {
53
         for (Person p : persons) {
52
-            assert (StringUtils.isPalindromeIgnoreCase(p.getName()));
54
+            String personName = p.getName();
55
+            assert (personName.startsWith(startingCharacter));
53
         }
56
         }
54
     }
57
     }
55
-}
58
+}

+ 2
- 1
src/test/java/com/zipcodewilmington/streams/anthropoid/TestPersonWarehouse.java View File

51
     public void testGetFirstNUniquelyNamedPeople() {
51
     public void testGetFirstNUniquelyNamedPeople() {
52
         int expectedSize = RandomUtils.createInteger(1, 3);
52
         int expectedSize = RandomUtils.createInteger(1, 3);
53
         int actualSize = (int)PersonWarehouse.getFirstNUniquelyNamedPeople(expectedSize).count();
53
         int actualSize = (int)PersonWarehouse.getFirstNUniquelyNamedPeople(expectedSize).count();
54
-        Assert.assertTrue(expectedSize > actualSize);
54
+        Assert.assertTrue(expectedSize >= actualSize);
55
     }
55
     }
56
 
56
 
57
     @Test
57
     @Test
95
         }
95
         }
96
         Assert.assertEquals(localNames.size(), warehouseNames.size());
96
         Assert.assertEquals(localNames.size(), warehouseNames.size());
97
     }
97
     }
98
+
98
 }
99
 }