Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Conversation

bill8white
Copy link

No description provided.

@@ -27,6 +26,12 @@ public DataProcessor(List<RoadAccident> roadAccidentList){
* @return
*/
public RoadAccident getAccidentByIndex7(String index){
Iterator<RoadAccident> iter = roadAccidentList.iterator();
while(iter.hasNext()) {
Copy link
Owner

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.

Copy link
Author

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

@bug-hunterx
Copy link
Owner

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.
I would recomend to peruse this book to remind yourself some general rules. http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

Looking forward to see Java 8 part!

.filter(r -> r.getAccidentId().equals(index))
.findFirst();

if (result.isPresent()) {
Copy link
Owner

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);

@bug-hunterx
Copy link
Owner

Great job Bill!
homework accepted!

@bug-hunterx
Copy link
Owner

Closing as homework is accepted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants