Storage - first solution#1896
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job implementing the core functionality of the Storage class. Your solution correctly handles adding, retrieving, and updating key-value pairs. However, changes are needed because a key checklist item was not met. In StorageImpl.java, the logic for finding a key's index is duplicated in both the put() and get() methods, which violates the 'Don't create repeating code' rule [CHECKLIST ITEM #5]. Please refactor this logic into a private helper method to eliminate the duplication. After you've addressed this, I'll be happy to take another look!
✨ 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
| for (int i = 0; i < size; i++) { | ||
| if (Objects.equals(key,keys[i])) { | ||
| values[i] = value; | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
This loop for finding an existing key is very similar to the one in the get method (lines 35-39). This violates checklist item #5: 'Don't create repeating code'. Consider extracting this logic into a private helper method that finds the index of a key. You can then call that method from both put() and get() to avoid duplication.
|
|
||
| import core.basesyntax.impl.StorageImpl; | ||
|
|
||
| public class Main { |
There was a problem hiding this comment.
This import is unused and can be safely removed.
| storage.put(33, box); | ||
| storage.size(); | ||
|
|
||
| System.out.println(storage.get(33)); |
There was a problem hiding this comment.
This method call has no effect because its return value is not assigned to any variable or used in any way. You can remove this line.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
slade13
left a comment
There was a problem hiding this comment.
The implementation is generally correct, but it uses Objects.equals(), which is explicitly forbidden in this task. Please replace this comparison with manual null-safe key comparison logic. After that, the solution should be fine.
| package core.basesyntax.impl; | ||
|
|
||
| import core.basesyntax.Storage; | ||
| import java.util.Objects; |
There was a problem hiding this comment.
Your implementation uses java.util.Objects, this directly violates the task checklist requirement:
Don't use class Objects
| @Override | ||
| public void put(K key, V value) { | ||
| for (int i = 0; i < size; i++) { | ||
| if (Objects.equals(key,keys[i])) { |
There was a problem hiding this comment.
There should be a space after the comma:
| if (Objects.equals(key,keys[i])) { | |
| if (Objects.equals(key, keys[i])) { |
slade13
left a comment
There was a problem hiding this comment.
Your code does not build now: https://github.com/mate-academy/jv-storage/actions/runs/23595932059/job/68712557766?pr=1896
Error: Failures:
Error: StorageImplTest.addTwoElementsWithSameKey:140 With two elements added with the same key, the value should be rewritten expected:<[Four]> but was:<[Two]>
Error: StorageImplTest.getElementWhenKeyIsObject:118 Test failed! Method get(key) should return correct value expected:<Element 2> but was:
Error: Errors:
Error: StorageImplTest.addTwoElementsWithNullKey:155 » NullPointer Key or value cannot be null.
Error: StorageImplTest.getElementWithKeyNull:82 » NullPointer Key or value cannot be null.
[INFO]
Error: Tests run: 8, Failures: 2, Errors: 2, Skipped: 0
The implementation has two functional issues. First, it rejects null keys, while this task expects null key support. Second, keys are compared with == instead of logical equality, so equal objects are not treated as the same key. Because of that, retrieving and replacing values by equal object keys does not work correctly.
mateuszwojtkowiak
left a comment
There was a problem hiding this comment.
Great job! The only thing that could be improved is repeated logic in two methods. The task is accepted, but please read my comment and create a helper method to avoid duplication.
| @Override | ||
| public void put(K key, V value) { | ||
|
|
||
| for (int i = 0; i < size; i++) { |
There was a problem hiding this comment.
You have duplicated key‑searching logic in both put() and get().
This violates the “Don’t repeat yourself” rule from the checklist.
Please extract this repeated logic into a private helper method, for example:
private int indexOfKey(K key) { ... }
Then call this method from both put() and get() to avoid code duplication.
No description provided.