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
8 changes: 4 additions & 4 deletions looptest.iml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
40 changes: 35 additions & 5 deletions src/main/java/com/zipcodewilmington/streams/StreamFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import com.zipcodewilmington.streams.tools.RandomUtils;
import com.zipcodewilmington.streams.tools.StringUtils;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;



/**
* Created by leon on 5/2/17.
*/
Expand All @@ -20,7 +24,8 @@ 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'));

}

/**
Expand Down Expand Up @@ -55,7 +60,12 @@ 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;
List<Person> list = new ArrayList<>();
personStream
.filter(p -> p.getName().startsWith(this.startingCharacter))
.collect(Collectors.toList());
return list;

}


Expand All @@ -64,16 +74,30 @@ public List<Person> toListMultiLine() {
* @return a list of person objects whose name starts with `this.startingCharacter`
*/ //TODO
public List<Person> toListOneLine() {
return null;

return personStream.filter(p -> p.getName().startsWith(this.startingCharacter)).collect(Collectors.toList());

}

// ----------------------------------THIS ALSO WORKS-------------------------------------------
//
// List<Person> list = personStream
// .filter(person -> startingCharacter.equals(person.getName().charAt(0)))
// .collect(Collectors.toList());
//
// return list;
//
// }


/**
* Using one-line lambda syntax
* @return an array of person object whose name starts with `this.startingCharacter`
*/ //TODO
public Person[] toArrayOneLine() {
return null;
Person[] pep = personStream.filter(person -> person.getName().startsWith(this.startingCharacter)).toArray(Person[]::new);

return pep;
}


Expand All @@ -82,7 +106,13 @@ public Person[] toArrayOneLine() {
* @return an array of person object whose name starts with `this.startingCharacter`
*/ //TODO
public Person[] toArrayMultiLine() {
return null;

Person[] pep = personStream
.filter(person -> person.getName().startsWith(this.startingCharacter))
.toArray(Person[]::new);
return pep;


}

}
13 changes: 10 additions & 3 deletions src/main/java/com/zipcodewilmington/streams/StreamMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ public class StreamMap {
* @return - a Stream of single characters
*/ //TODO
public static Stream<String> letters(String someWord) {
return null;
return Arrays.stream(someWord.split(""));
// String[] characters = someWord.split("");
//
// return Stream.of(characters);
}

/**
* @param someWords - variable amount of String arguments
* @return - a Stream of several Streams of single characters
*/ //TODO
public static Stream<Stream<String>> wordsMap(String... someWords) {
return null;
return Arrays.stream(someWords).map(StreamMap::letters);
// return Stream.of(someWords).map(w -> letters(w));
}

/**
* @param stringArray - variable amount of String arguments
* @return - a Stream of several Streams of single characters
*/ //TODO
public static Stream<String> wordsFlatMap(String... stringArray) {
return null;
return Arrays.stream(stringArray).flatMap(StreamMap::letters);

// return Stream.of(stringArray).sorted().flatMap((w -> letters(w)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 +53,12 @@ public List<Person> createPersonList(int listSize) {
* @return - Array of Person objects
*/ // TODO
public Person[] createPersonArray(int arrayLength) {
return null;
Person[] arrayDperson = Stream
.generate(this::createRandomPerson)
.limit(arrayLength)
.toArray(Person[]::new);

return arrayDperson;
}


Expand All @@ -59,6 +69,10 @@ public Person[] createPersonArray(int arrayLength) {
* @return - Stream representation of collection of Person objects
*/ // TODO
public Stream<Person> createPersonStream(int streamCount) {
return null;
Stream<Person> stremOfPerson = Stream
.generate(this::createRandomPerson)
.limit(streamCount);

return stremOfPerson;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
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.stream.Collectors;
import java.util.stream.Stream;

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



return nombres;
}


/**
* @return list of uniquely named Person objects
*/ //TODO
public Stream<Person> getUniquelyNamedPeople() {
return null;

Set<String> setH = new HashSet<>(people.size());
return people.stream().filter(person -> setH.add(person.getName()));



}


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


}

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

/**
* @return a mapping of Person Id to the respective Person name
*/ // TODO
public Map<Long, String> getIdToNameMap() {
return null;
Map<Long, String> mapIdAnom = people // tabien puesde ser sin el mapy poner people.stram()............( y quitar el return de abajo)
.stream()
.collect(Collectors.toMap(Person::getPersonalId, Person::getName));
return mapIdAnom;
}


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


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




}






// DO NOT MODIFY
public Boolean contains(Person p) {
return people.contains(p);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zipcodewilmington.streams.conversions;

import com.zipcodewilmington.streams.StreamMap;
import com.zipcodewilmington.streams.anthropoid.Person;
import com.zipcodewilmington.streams.anthropoid.PersonFactory;

Expand All @@ -25,12 +26,15 @@ public ArrayConverter(int collectionSize) {

//TODO
public List<Person> toList() {
return null;

return Arrays.asList(super.objectSequence);

}

//TODO
public Stream<Person> toStream() {
return null;
return Arrays.stream(super.objectSequence);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ public List<Person> toList() {

//TODO
public Stream<Person> toStream() {
return null;
return super.objectSequence.stream();
// Stream<Person> peps = objectSequence
// .stream();
// return peps;
}

//TODO
public Person[] toArray() {
return null;
return super.objectSequence.toArray(new Person[0]);
}
// Person[] nuevo = objectSequence
// .stream()
// .toArray(Person[]::new);
// return nuevo;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,30 @@ public StreamConverter(int collectionSize) {

// TODO
public List<Person> toList() {
return null;
return personList;
}
// List<Person> po = personList;
//
// return po;
// }

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

// TODO
public Person[] toArray() {
return null;

return personList.toArray(new Person[0]);
}
// Person[] po = personList
// .stream()
// .toArray(Person[]::new);
// return po;
// }
}