-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ready for push, passed tests and checkstyle #1920
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?
Changes from 1 commit
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 |
|---|---|---|
| @@ -1,19 +1,49 @@ | ||
| package core.basesyntax.impl; | ||
|
|
||
| import core.basesyntax.Storage; | ||
| import java.util.Objects; | ||
|
|
||
| public class StorageImpl<K, V> implements Storage<K, V> { | ||
| private static final int MAX_CAPACITY = 10; | ||
| private K [] key; | ||
| private V [] value; | ||
|
Comment on lines
+7
to
+8
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. The variable names 'key' and 'value' (lines 8-9) are not informative. Consider using plural forms like 'keys' and 'values' since they store multiple elements. |
||
| private int size; | ||
|
|
||
| public StorageImpl() { | ||
| this.key = (K[]) new Object[MAX_CAPACITY]; | ||
| this.value = (V[]) new Object[MAX_CAPACITY]; | ||
| this.size = 0; | ||
| } | ||
|
|
||
| @Override | ||
| public void put(K key, V value) { | ||
| for (int i = 0; i < size; i++) { | ||
| if (Objects.equals(this.key[i], key)) { | ||
|
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. Checklist item #5 states 'Don't create repeating code'. The key comparison logic in |
||
| this.value[i] = value; | ||
| return; | ||
| } | ||
| } | ||
| if (size < MAX_CAPACITY) { | ||
| this.key[size] = key; | ||
| this.value[size] = value; | ||
| size++; | ||
| } else { | ||
| System.out.println("Array is full"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public V get(K key) { | ||
| for (int i = 0; i < size; i++) { | ||
| if (Objects.equals(this.key[i], key)) { | ||
|
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. Checklist item #5: Same repeating pattern issue as line 21. The key search loop exists in both |
||
| return this.value[i]; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @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 item #6 states 'Don't use class Objects'. Replace
Objects.equals()with direct null-safe comparison or use.equals()method on the key objects.