Repository navigation
Sheffield | 26-Java-June | Hassan Osman | Sprint 4 | Prep: Streams and Optionals - #73
HassanOHOsman wants to merge 25 commits into
Conversation
2. Git-ignore files and folders that should not be tracked.
… to print to the console all names start with A (case in-sensitive). 2. Construct a Main class with main method inside, create a StreamExercise isntance and class the printNamesStartingWithA from there.
…th the requirements.
…ass. The method returns all names start with a vowel, capitalized, and in a reverse alphabetical order.
…ass. The method returns all names start with a vowel, capitalized, and in a reverse alphabetical order. 2. Remove samples aimed for debugging and logging from the main method
…- that takes 1) a map containing shapes and their respective number of sides, and 2) the number of sides. It returns the number of shapes that has that number of sides.
…the remainders of the division of numbers from 1 -20 inclusive by any divisor (integer), comma-separated.
…the remainders of the division of numbers from 1 -20 inclusive by any divisor (integer), comma-separated.
jacknewman1995
left a comment
There was a problem hiding this comment.
Nice work, have added some relatively minor comments. Mainly just check in future that you're only pushing your java files in PRs.
There was a problem hiding this comment.
Shouldn't be including these - add them to gitignore
There was a problem hiding this comment.
Likewise for other PRs not just yours, probably something good to reiterate with the group
There was a problem hiding this comment.
Shouldn't be including these - add them to gitignore
By bad! Sorted now. Thank you :)
| .filter(name -> name.toUpperCase().startsWith("A")) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| System.out.println(namesStartsWithA); |
There was a problem hiding this comment.
Nice! Can you do the printing without needing to create the list or any other variable?
There was a problem hiding this comment.
Yes, we can. I don't know for whatever reason I presumed that the stream out should be packaged back into a list.
|
|
||
| public void vowelNamesCapitalisedDescending(List<String> listOfNames) { | ||
| List<String> namesStartsWithVowel = listOfNames.stream() | ||
| .filter(name -> name.toUpperCase().matches("^[AEIOUaeiou].*")) |
There was a problem hiding this comment.
Do we need the lowercase in the regex given we've said toUpperCase?
There was a problem hiding this comment.
Yeah, not so intelligent from myself lol since I am already using .toUpperCase beforehand. Corrected. Thank you!
| public class Remainders { | ||
|
|
||
| public void printRemainders(int divisor) { | ||
| String remainders = ""; |
There was a problem hiding this comment.
Is a string the best data structure for storing numbers?
There was a problem hiding this comment.
It is definitely not. Again, perhaps I've misread the requirements. Anyway, I've used a List of Integers instead and updated the rest of the code block. Thank you :)
|
|
||
| public void printRemainders(int divisor) { | ||
| String remainders = ""; | ||
| for (int i = 1; i <= 20; i ++) { |
There was a problem hiding this comment.
How come we aren't streaming here?
| int remainder = i % divisor; | ||
| if (i < 20) { | ||
| remainders += remainder + ","; | ||
| } else { |
There was a problem hiding this comment.
Bit clunky! How can we avoid this by using more appropriate data structures?
|
|
||
| public Map<Integer, List<Integer>> remainderGroups(int divisor) { | ||
|
|
||
| Map<Integer, List<Integer>> result = IntStream.rangeClosed(1, 20) |
|
|
||
| public Map<Integer, Long> remainderCounts(int divisor) { | ||
|
|
||
| Map<Integer, Long> result = IntStream.rangeClosed(1, 20) |
|
|
||
| public int countShapesWithSides(Map<String, Integer> shapesToSides, int numberOfSides) { | ||
|
|
||
| int numOfShapesWithThatNumOfSides = (int) shapesToSides.values().stream() |
There was a problem hiding this comment.
For some reason by brains defaults to "int". Anyway, since the stream operation gives a long, I've updated the code block by removing the casting to "int" parts. Also, changed the type to "long" in the method signature.
There was a problem hiding this comment.
Looks like a load of .class files have been committed here? Should be just .java as .class is the compiled bytecode which I may struggle to read..!
There was a problem hiding this comment.
I am really sorry Jack! I've run terminal commands and all the .class file in this branch are untracked. I however now added them specifically into my .gitignore. Please let me know if this is still an issue. I am really sorry.
…ithout packaging back into a list prior to printing.
…much more appropriate data type.
Hi Jack! Thank you for taking the time to review my work. I've changed my code as per your request. please review and let me know if there's anything else you want me to fix. On a side note, as per my checks all .class files are not git-tracked. I don't know why they still show. Anyway, I've now added .class specifically inside my .gitignore file. |
Self checklist
In this PR, I implemented solutions revolve around the use of streams with collections.