Skip to content

Second jump search#2

Open
oleksiipet wants to merge 6 commits into
hyperskill:masterfrom
oleksiipet:second-jump-search
Open

Second jump search#2
oleksiipet wants to merge 6 commits into
hyperskill:masterfrom
oleksiipet:second-jump-search

Conversation

@oleksiipet

Copy link
Copy Markdown

No description provided.

Comment thread src/phonebook/Contact.java Outdated

public class Contact {

private String number;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the class does not have setters at all, you may declare fields as final

Comment thread 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I think it is reasonable to use Objects here. And think if java.util.Optional; class is appropriate to return from search method?

Comment thread 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chain does not look very good.

Comment thread src/phonebook/Main.java

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(" ")),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good approach with functional style!

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.

3 participants