Skip to content

Solution#1921

Open
mykhalenych wants to merge 1 commit into
mate-academy:masterfrom
mykhalenych:develop
Open

Solution#1921
mykhalenych wants to merge 1 commit into
mate-academy:masterfrom
mykhalenych:develop

Conversation

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

The implementation correctly fulfills all core functional requirements including generic Storage<K,V> interface, put/get/size methods with proper key replacement logic, and array-based storage with MAX_SIZE=10. No collections were used as required. The main issues identified are non-blocking concerns: the duplicate StorageImpl.java file in the wrong package can be simply deleted; the null-safe comparison logic works correctly due to Java's short-circuit evaluation (key != null && key.equals(keys[i])), but extracting this into a private findKeyIndex(K key) helper method would improve code organization per DRY principles; empty lines between methods in Application.java are a minor style preference. Optional improvements to consider: delete src/main/java/core/basesyntax/StorageImpl.java since the correct implementation is in the impl subpackage; extract the duplicated key-searching loop into a reusable private method for cleaner code; remove any blank lines between method implementations in Application.java. Your solution is approved and meets the task requirements. The core functionality works correctly - these are code quality suggestions rather than blockers.


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

Footnotes

  1. Rate AI review example

@Override
public void put(K key, V value) {
for (int i = 0; i < size; i++) {
if (key == keys[i] || (key != null && key.equals(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.

This will throw NullPointerException if key is null. The expression key == keys[i] is evaluated first, and if key is null, it becomes null == keys[i], but if keys[i] is also null, Java still evaluates the left side as false. However, if keys[i] is not null, calling .equals() on null throws NPE. Use null-safe comparison: key == null && keys[i] == null || key != null && key.equals(keys[i])

@Override
public V get(K key) {
for (int i = 0; i < size; i++) {
if (key == keys[i] || (key != null && key.equals(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.

This has the same null-handling issue as line 20. When key is null, key.equals(keys[i]) will throw NPE.

Comment on lines +19 to +35
for (int i = 0; i < size; i++) {
if (key == keys[i] || (key != null && key.equals(keys[i]))) {
values[i] = value;
return;
}
}
if (size < MAX_SIZE) {
keys[size] = key;
values[size] = value;
size++;
}
}

@Override
public V get(K key) {
for (int i = 0; i < size; i++) {
if (key == keys[i] || (key != null && key.equals(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.

The null-checking logic in put() and get() methods is identical. Per DRY principle, extract this into a private helper method like findKeyIndex(K key) to avoid code duplication.

Comment on lines +1 to +3
package core.basesyntax;

public class StorageImpl<K, V> implements Storage<K, V> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing import statement. This file cannot implement Storage interface without importing it. Add: import core.basesyntax.Storage;

Comment on lines +18 to +29
values[i] = value;
return;
}
}
if (size < MAX_SIZE) {
keys[size] = key;
values[size] = value;
size++;
}
}

@Override
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 key-searching loop logic is duplicated in the get() method. Consider extracting this into a private helper method like findKeyIndex(K key) to follow DRY principle (checklist item #5).

Comment on lines +32 to +39
if (key == null && keys[i] == null || key != null && key.equals(keys[i])) {
return values[i];
}
}
return null;
}

@Override
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 key-searching loop logic duplicates code from put() method. Extract to a private helper method to follow DRY principle (checklist item #5).

System.out.println("Storage size: " + storage.size());

storage.put(1, "NewValue1");
System.out.println("Get updated value by key 1: " + storage.get(1));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Per checklist requirements, remove empty lines between method implementations. There should be no blank line after line 15 before the next method.

import core.basesyntax.impl.StorageImpl;

public class Application {
public static void main(String[] args) {
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 constant name MAX_SIZE is not fully informative. Consider renaming to MAX_STORAGE_CAPACITY to clearly indicate its purpose.

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.

2 participants