-
Notifications
You must be signed in to change notification settings - Fork 1.7k
i have done #1913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
i have done #1913
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,51 @@ | |
| import core.basesyntax.Storage; | ||
|
|
||
| public class StorageImpl<K, V> implements Storage<K, V> { | ||
| private static final int MAX_STORAGE_CAPACITY = 10; | ||
| private final Object[] keys; | ||
| private final Object[] values; | ||
| private int size; | ||
|
|
||
| public StorageImpl() { | ||
| keys = new Object[MAX_STORAGE_CAPACITY]; | ||
| values = new Object[MAX_STORAGE_CAPACITY]; | ||
| size = 0; | ||
| } | ||
|
|
||
| @Override | ||
| public void put(K key, V value) { | ||
| for (int i = 0; i < size; i++) { | ||
|
|
||
| if (keys[i] == null ? key == null : keys[i].equals(key)) { | ||
|
|
||
| values[i] = value; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| keys[size] = key; | ||
| values[size] = value; | ||
|
|
||
| size++; | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public V get(K key) { | ||
|
Comment on lines
35
to
36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line at start of method implementation - remove redundant empty line. |
||
| for (int i = 0; i < size; i++) { | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaces existing key's value - uses Objects.equals which is not allowed per checklist requirements. |
||
| if (keys[i] == null ? key == null : keys[i].equals(key)) { | ||
|
|
||
| return (V) values[i]; | ||
| } | ||
|
|
||
| } | ||
| return null; | ||
|
|
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line at start of method implementation - remove redundant empty line. |
||
|
|
||
| @Override | ||
| public int size() { | ||
| return -1; | ||
| return size; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHECKLIST VIOLATION #4: This null-safe equality check is duplicated in
get()method at line 39. Extract this logic into a private helper method (e.g.,areKeysEqual(Object storedKey, K searchKey)) to follow the DRY principle.