Open
Conversation
swsms
reviewed
Dec 27, 2018
src/phonebook/Contact.java
Outdated
|
|
||
| public class Contact { | ||
|
|
||
| private String number; |
There was a problem hiding this comment.
Since the class does not have setters at all, you may declare fields as final
src/phonebook/Main.java
Outdated
| int lo = 0, hi = Math.min(sqr, contacts.size() - 1); | ||
| while (lo < hi) { | ||
| Contact contact = contacts.get(hi); | ||
| if (contact.getName().compareTo(name) == 0) { |
There was a problem hiding this comment.
The utility class Objects has a set of convenient methods which provides null-safety instead of object.method1().method2() and so on. And they are more readable as well.
Author
There was a problem hiding this comment.
Thanks I think it is reasonable to use Objects here. And think if java.util.Optional; class is appropriate to return from search method?
src/phonebook/Main.java
Outdated
| private static void bubbleSort(List<Contact> contacts) { | ||
| for (int i = 0; i < contacts.size(); i++) { | ||
| for (int j = contacts.size() - 1; j > i; j--) { | ||
| if (contacts.get(j).getName().compareTo(contacts.get(j - 1).getName()) < 0) { |
|
|
||
| private static List<Contact> parseContacts() throws IOException { | ||
| Stream<String> directoryLines = Files.lines(Paths.get(CONTACT_DATA_DIRECTORY)); | ||
| return directoryLines.map(line -> new Contact(line.substring(0, line.indexOf(" ")), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.