Skip to content

Conversation

Lyten1
Copy link

@Lyten1 Lyten1 commented Aug 1, 2025

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Thank you for your hard work! Before your PR can be approved, please address the following critical issues:

  • In MyHashMap.java, the constructor does not initialize the table or threshold, which can cause runtime errors. The resize method also doesn't update the threshold correctly, and the put method increments size even when updating existing keys.
  • In Bus.java, the hashCode() method does not handle possible null values for model or color, which can lead to NullPointerException.
    Please fix these issues so your code meets the core requirements. You're almost there—keep going! 🚀

✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


private Node<K, V>[] table;

public MyHashMap() {

Choose a reason for hiding this comment

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

Issue: The constructor does not initialize the table or threshold. According to the checklist, the initial capacity and threshold should be set up in the constructor. Consider initializing the table and threshold here.

tableLength = (tab = resize()).length;
}
if ((nodeAtPosition = tab[pointer = (hash & tableLength - 1)]) == null) {
tab[pointer] = new Node<>(key, value, hash, null);

Choose a reason for hiding this comment

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

Issue: In the put method, size is incremented regardless of whether a new key is added or an existing key is updated. According to the checklist, the size should only increase when a new key-value pair is added, not when updating an existing key.

}
}
if (++size > threshold) {
resize();

Choose a reason for hiding this comment

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

Issue: The resize method is called after incrementing size, but the threshold may not be set correctly if the table was not initialized in the constructor. Ensure threshold is always set appropriately after resizing or initialization.

public int hashCode() {
return 0;
int result = 31;
result = 17 * result + model.hashCode();

Choose a reason for hiding this comment

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

Issue: The hashCode() method does not handle the case where model is null. According to the checklist, you should handle possible null values for fields in hashCode().

return 0;
int result = 31;
result = 17 * result + model.hashCode();
result = 17 * result + color.hashCode();

Choose a reason for hiding this comment

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

Issue: The hashCode() method does not handle the case where color is null. According to the checklist, you should handle possible null values for fields in hashCode().

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Thank you for your hard work! 😊 Your implementation is almost complete, but there is one critical issue left: in your MyHashMap, the put method increments size even when updating an existing key. According to the requirements, size should only increase when a new key-value pair is added. Please adjust your logic so that size is only incremented for new keys. Once you fix this, your code will fully meet the task requirements! Keep it up! 🚀


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 57 to 59
if (++size > threshold) {
resize();
}

Choose a reason for hiding this comment

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

Issue: The size variable is incremented every time put is called, even when updating an existing key. According to the checklist, size should only be incremented when a new key-value pair is added, not when updating an existing key. Please adjust the logic so that size is only incremented when a new node is actually inserted.

Copy link
Author

Choose a reason for hiding this comment

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

if (existingMapping != null) {
existingMapping.setValue(value);
return;
}

I have here return, which prevent changing size within updating value

Choose a reason for hiding this comment

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

привіт, твій блок коду виконується не в тій гілці до якої є зауваження, тобто потенційно проблема яку зазначив ШІ може виникати

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great work! 🚀 Your implementation of MyHashMap now fully meets all the requirements and best practices outlined in the task. The critical issue with the size incrementation has been resolved, and your code is clean, well-structured, and easy to maintain. All necessary methods are present, constants are used appropriately, and your classes are well-parameterized and follow Java conventions. There are no missing functionalities or unnecessary files. No further changes are required—your code is ready for submission! Keep up the excellent work and continue applying these best practices in future projects.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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