-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bill Bai homework #3
Conversation
@@ -27,6 +26,12 @@ public DataProcessor(List<RoadAccident> roadAccidentList){ | |||
* @return | |||
*/ | |||
public RoadAccident getAccidentByIndex7(String index){ | |||
Iterator<RoadAccident> iter = roadAccidentList.iterator(); | |||
while(iter.hasNext()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recomend to use for(accident: list) kind of syntax - no need to create iterator by yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's a homework, I'd like to try more way to implement it.
In other function, I use the for(:) style
Bill - I really like all your solutions for java 7 tasks. You used all possible guava collections in various different ways - good job! General points to improve is only about clean code practices. Variable names, commented code, if statements without brackets - these are not the best things to do. Looking forward to see Java 8 part! |
.filter(r -> r.getAccidentId().equals(index)) | ||
.findFirst(); | ||
|
||
if (result.isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional has method orElse(value) that returns "value" if result is not present. so you can solve this task in one line
return stream.blah.blah.orElse(null);
Great job Bill! |
Closing as homework is accepted |
No description provided.