Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions looptest.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_10">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand All @@ -10,10 +10,10 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.5" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.5" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.13.0-rc1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.13.0-rc1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.13.0-rc1" level="project" />
</component>
</module>
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
Expand Down
35 changes: 28 additions & 7 deletions src/main/java/com/zipcodewilmington/streams/StreamFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.zipcodewilmington.streams.tools.RandomUtils;
import com.zipcodewilmington.streams.tools.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -20,23 +21,24 @@ public class StreamFilter {
* No arg constructor
*/ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
public StreamFilter() {
this(Stream.empty(), null);
this(new PersonFactory().createPersonStream(100), RandomUtils.createCharacter('A', 'Z'));
}

/**
* @param people - Array of person objects
* @param startingCharacter - character to filter by
*/ //TODO
public StreamFilter(Person[] people, Character startingCharacter) {
this(Stream.empty(), null);

this(Arrays.stream(people), startingCharacter);
}

/**
* @param people - List of person objects
* @param startingCharacter - character to filter by
*/ //TODO
public StreamFilter(List<Person> people, Character startingCharacter) {
this(Stream.empty(), null);
this(people.stream(), startingCharacter);
}


Expand All @@ -55,7 +57,15 @@ public StreamFilter(Stream<Person> people, Character startingCharacter) {
* @return a list of person object whose name starts with `this.startingCharacter`
*/ //TODO
public List<Person> toListMultiLine() {
return null;
return personStream
.filter(person -> {
if (startingCharacter.equals(person.getName().charAt(0))){
return true;
}
return false;
})
.collect(Collectors.toList());

}


Expand All @@ -64,7 +74,9 @@ public List<Person> toListMultiLine() {
* @return a list of person objects whose name starts with `this.startingCharacter`
*/ //TODO
public List<Person> toListOneLine() {
return null;
List <Person> personList = personStream.filter(person -> startingCharacter.equals(person.getName().charAt(0))).collect(Collectors.toList());

return personList;
}


Expand All @@ -73,7 +85,8 @@ public List<Person> toListOneLine() {
* @return an array of person object whose name starts with `this.startingCharacter`
*/ //TODO
public Person[] toArrayOneLine() {
return null;
Person[] personArray = personStream.filter(person -> startingCharacter.equals(person.getName().charAt(0))).toArray(Person[]::new);
return personArray;
}


Expand All @@ -82,7 +95,15 @@ public Person[] toArrayOneLine() {
* @return an array of person object whose name starts with `this.startingCharacter`
*/ //TODO
public Person[] toArrayMultiLine() {
return null;
return personStream
.filter(person -> {
if (startingCharacter.equals(person.getName().charAt(0))){
return true;
}
return false;
})
.toArray(Person[]::new);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.zipcodewilmington.streams.tools.RandomUtils;
import com.zipcodewilmington.streams.tools.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -39,7 +40,12 @@ public Person createRandomPerson() {
* @return - ArrayList of Person objects
*/ // TODO
public List<Person> createPersonList(int listSize) {
return null;
List<Person> personList = Stream
.generate(this :: createRandomPerson)
.limit(listSize)
.collect(Collectors.toList());

return personList;
}


Expand All @@ -48,7 +54,12 @@ public List<Person> createPersonList(int listSize) {
* @return - Array of Person objects
*/ // TODO
public Person[] createPersonArray(int arrayLength) {
return null;
Person[] personArray =
Stream
.generate(this::createRandomPerson)
.limit(arrayLength)
.toArray(Person[]::new);
return personArray;
}


Expand All @@ -59,6 +70,9 @@ public Person[] createPersonArray(int arrayLength) {
* @return - Stream representation of collection of Person objects
*/ // TODO
public Stream<Person> createPersonStream(int streamCount) {
return null;
Stream<Person> pStream = Stream
.generate(this::createRandomPerson)
.limit(streamCount);
return pStream;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import com.zipcodewilmington.streams.tools.logging.LoggerHandler;
import com.zipcodewilmington.streams.tools.logging.LoggerWarehouse;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -36,15 +35,37 @@ public void addPerson(Person person) {
* @return list of names of Person objects
*/ // TODO
public List<String> getNames() {
return null;
List<String> myPeoplesNames =
people.stream()
.map(Person::getName)
.collect(Collectors.toList());

return myPeoplesNames;
}


/**
* @return list of uniquely named Person objects
*/ //TODO
public Stream<Person> getUniquelyNamedPeople() {
return null;
List<String> names = getNames().stream().distinct().collect(Collectors.toList());
List<Person> unique = new ArrayList<>();
for (Person person: people) {
if(names.contains(person.getName())){
unique.add(person);
names.remove(person.getName());
}

}
Stream<Person> uniquePeeps = unique.stream();
// Predicate<Person> matchNames = val -> names.contains(val.getName());;
//
// Stream<Person> uniquePeeps = people
// .stream()
// .sorted(Person::compareTo);
// //.filter(val -> names.contains(val.getName()));

return uniquePeeps;
}


Expand All @@ -53,38 +74,56 @@ public Stream<Person> getUniquelyNamedPeople() {
* @return a Stream of respective
*/ //TODO
public Stream<Person> getUniquelyNamedPeopleStartingWith(Character character) {
return null;
Stream<Person> sameLetter = getUniquelyNamedPeople()
.filter(person -> person.getName().charAt(0) == character);


return sameLetter;
}

/**
* @param n first `n` Person objects
* @return a Stream of respective
*/ //TODO
public Stream<Person> getFirstNUniquelyNamedPeople(int n) {
return null;
Stream<Person> first = getUniquelyNamedPeople().limit(n);
return first;
}

/**
* @return a mapping of Person Id to the respective Person name
*/ // TODO
public Map<Long, String> getIdToNameMap() {
return null;
Map <Long, String> nameMap = people
.stream()
.collect(Collectors.toMap(Person::getPersonalId, Person::getName));

return nameMap;
}




/**
* @return Stream of Stream of Aliases
*/ // TODO
public Stream<Stream<String>> getNestedAliases() {
return null;
Stream<Stream<String>> nested =
people.stream()
.map(val ->Arrays.stream(val.getAliases()));

return nested;
}


/**
* @return Stream of all Aliases
*/ // TODO
public Stream<String> getAllAliases() {
return null;
Stream<String> aliases = people
.stream()
.flatMap(val-> Arrays.stream(val.getAliases()));
return aliases;
}

// DO NOT MODIFY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public ArrayConverter(int collectionSize) {

//TODO
public List<Person> toList() {
return null;
List<Person> peopleList = Arrays.stream(this.objectSequence).collect(Collectors.toList());
return peopleList;
}

//TODO
public Stream<Person> toStream() {
return null;

return Arrays.stream(this.objectSequence);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.zipcodewilmington.streams.anthropoid.Person;
import com.zipcodewilmington.streams.anthropoid.PersonFactory;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -29,11 +30,11 @@ public List<Person> toList() {

//TODO
public Stream<Person> toStream() {
return null;
return toList().stream();
}

//TODO
public Person[] toArray() {
return null;
return toList().toArray(new Person[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ public StreamConverter(int collectionSize) {

// TODO
public List<Person> toList() {
return null;
List <Person> people = personList.stream().collect(Collectors.toList());
return people;
}

// TODO
public Stream<Person> toStream() {
return null;
Stream <Person> people = toList().stream();

return people;
}

// TODO
public Person[] toArray() {
return null;
Person[] people = toStream().toArray(Person[]::new);

return people;
}
}