Skip to content

Storage - first solution#1896

Open
mate-student26 wants to merge 5 commits into
mate-academy:masterfrom
mate-student26:Storage
Open

Storage - first solution#1896
mate-student26 wants to merge 5 commits into
mate-academy:masterfrom
mate-student26:Storage

Conversation

@mate-student26
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +20 to +25
for (int i = 0; i < size; i++) {
if (Objects.equals(key,keys[i])) {
values[i] = value;
return;
}
}
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 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 {
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 import is unused and can be safely removed.

storage.put(33, box);
storage.size();

System.out.println(storage.get(33));
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 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.

Copy link
Copy Markdown

@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.

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.

Copy link
Copy Markdown

@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.

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.

Copy link
Copy Markdown

@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.

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.

Copy link
Copy Markdown

@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.

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.

Copy link
Copy Markdown

@slade13 slade13 left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be a space after the comma:

Suggested change
if (Objects.equals(key,keys[i])) {
if (Objects.equals(key, keys[i])) {

@mate-student26 mate-student26 requested a review from slade13 March 26, 2026 13:14
Copy link
Copy Markdown

@slade13 slade13 left a comment

Choose a reason for hiding this comment

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

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.

@mate-student26 mate-student26 requested a review from slade13 May 4, 2026 13:12
Copy link
Copy Markdown

@mateuszwojtkowiak mateuszwojtkowiak left a comment

Choose a reason for hiding this comment

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

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++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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.

4 participants